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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started