Question: How can you convert these JavaScript functions to a PHP class to be inserted into a .php file? //Constructor for the Question function Question(category,question,answers){ //How

How can you convert these JavaScript functions to a PHP class to be inserted into a .php file?

//Constructor for the Question function Question(category,question,answers){ //How many arguments are provided var nArgs=arguments.length;//The number of arguments passed to the function if(nArgs==0||nArgs>3){//Empty Question this.cat=""; this.qstn=""; }else if(nArgs==3){//Question provided with all inputs this.cat=category; this.qstn=question; this.ans=answers; }else if(nArgs==2){//Question provided with no answers added latter this.cat=category; this.qstn=question; }else{ this.cat=category.cat; this.qstn=category.qstn; this.ans=category.ans; } }; //Setting the Category Question.prototype.setCat=function(category){ this.cat=category; }; //Setting the Question Question.prototype.setQstn=function(question){ this.qstn=question; }; //Adding an Answer Question.prototype.addAns=function(answer){ this.ans.push(answer); }; //Accessing the Category Question.prototype.getCat=function(){ return this.cat; }; //Accessing the Question Question.prototype.getQstn=function(){ return this.qstn; }; //Accessing one of the Answers Question.prototype.getAns=function(number){ if(number>=0&&number"+this.qstn+"

"); for(var i=0;i0) document.write('

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!