DEV Community

HY-SHEN
HY-SHEN

Posted on

Something is missing?

// Write your program here, create suitable objects and put them in the args variable, so that the following code can work normally

let result;
if(args.op=="+"){
result=args.n1+args.n2;
}else if(args.op=="-"){
result=args.n1-args.n2;
}else{
result="Not supported";
}
console.log(result);

Please help me to answer the masters and gods

Top comments (2)

Collapse
 
okyanusoz profile image
okyanusoz • Edited

Use parseInt() to parse the integers.

Fixed code:

// Write your program here, create suitable objects and put them in the args variable, so that the following code can work normally

let result;
if(args.op=="+"){
   result=parseInt(args.n1)+parseInt(args.n2);
}else if(args.op=="-"){
   result=parseInt(args.n1)-parseInt(args.n2);
}else{
      result="Not supported";
}
console.log(result);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
justjoe profile image
Joegie Wagwag • Edited

let args = [Object here]; // create suitable objects and put them in the args variable