Which one is helpful? modify the PHP function to a JS function. thank you! Functionbmrs ($ weight0, $ sex1, $ age) {switch ($ age) {case $ age & gt; 0and $ age & lt; 3: $ xarray (1 & gt; array (60.9,-54), 2 & gt; array (61.0,-51); $ y1 which helps you to change the PHP function to a JS function. thank you!
Function bmrs ($ weight = 0, $ sex = 1, $ age ){
Switch ($ age ){
Case $ age> = 0 and $ age <3:
$ X = array (1 => array (60.9,-54), 2 => array (61.0,-51 ));
$ Y = 1;
Break;
Case $ age> = 3 and $ age <10:
$ X = array (1 => array (22.7, 495), 2 => array (22.5, 499 ));
$ Y = 1;
Break;
Case $ age> = 10 and $ age <18:
$ X = array (1 => array (17.5, 651), 2 => array (12.2, 746 ));
$ Y = 1;
Break;
Case $ age> = 10 and $ age <18:
$ X = array (1 => array (17.5, 651), 2 => array (12.2, 746 ));
$ Y = 0.95;
Break;
Case $ age> = 18 and $ age <30:
$ X = array (1 => array (15.3, 679), 2 => array (14.7, 496 ));
$ Y = 0.95;
Break;
Case $ age> = 30 and $ age <60:
$ X = array (1 => array (11.6, 879), 2 => array (8.7, 829 ));
$ Y = 0.95;
Break;
Case $ age> = 60:
$ X = array (1 => array (13.5, 487), 2 => array (10.5, 596 ));
$ Y = 0.95;
Break;
Default:
Break;
}
Return ceil ($ x [$ sex] [0] * $ weight + $ x [$ sex] [1]) * $ y); // round the floating point number
}
Which of the following are built-in parameters? are the first two default values? $ Weight = 0, $ sex = 1, $ age
These two codes are modified to JS, and the difficulty is:
Case $ age> = 0 and $ age <3:
$ X = array (1 => array (60.9,-54), 2 => array (61.0,-51 ));
Which of the following is a favor? change it to JavaScript. thank you.
------ Solution --------------------
JScript code
function bmrs(weight,sex,age){ var x=new Array(2),y=null; switch (true) { case age>=0 && age<3: x[1]=new Array(60.9,-54),x[2]=new Array(61.0,-51); y=1; break; case age>=3 && age<10: x[1]=new Array(22.7,495),x[2]=new Array(22.5,499); y=1; break; case age>=10 && age<18: x[1]=new Array(17.5,651),x[2]=new Array(12.2,746); y=1; break; case age>=10 && age<18: x[1]=new Array(17.5,651),x[2]=new Array(12.2,746); y=0.95; break; case age>=18 && age<30: x[1]=new Array(15.3,679),x[2]=new Array(14.7,496); y=0.95; break; case age>=30 && age<60: x[1]=new Array(11.6,879),x[2]=new Array(8.7,829); y=0.95; break; case age>=60: x[1]=new Array(13.5,487),x[2]=new Array(10.5,596); y=0.95; break; default: break; } return Math.ceil((x[1][0]*weight+x[1][1])*y); }