I’m unable to pass only one of the five tests. I’m stuck when the input values are (5, 3, $) and the output should be “NaN” however, I’m getting this undesired output value 1.6666666666666667
Shouldn’t $ automatically go to the last else block and accept NaN? Why is it printing this strange value 1.6666666666666667?
I have noticed no matter whatever I assigned to ans in the last else block, the ans output is always showing 1.6666666666666667 I suspect it could be an issue with whatever that’s testing the code in the code editor on the website.
Here is my code:
left_operand = left_operand; // Left operand is assigned here
right_operand = right_operand; // Right operand is assigned here
operator = operator; // This is the String representation of operator
ans = ans; // Assign final answer to ans
// Following is an Array of all possible operators
let all_operators= ['+','-','*','/'];
if(operator === '+') {
// when operator is '+' then
ans = left_operand + right_operand;
} else if(operator === '-') {
// when operator '-' then
ans = left_operand - right_operand;
} else if(operator === '*') {
// when operator '*' then
ans = left_operand * right_operand;
} else if(operator = '/') {
// when operator '/' then
ans = left_operand / right_operand;
} else {
// otherwise NaN
ans = NaN;
}
console.log(`ans value is ${ans}`);
I checked the solution, I’m unable to figure out why this solution does not work?