I have the code below. Now I want to run an if-else statement on it, but it’s not working. Any idea with this?
var num1 = $('#id1').val();
var num2 = $('#id2').val();
var newVal = (num1+2)*(num2/4);
var nextVal =(num1+4)*(num2/2);
var newArr = new Array();
newArr.push(newVal);
newArr.push(nextVal);
newArr.sort();
if(newArr.get(0)==newVal)
$("body").html("<p>works fine!</p>");
else $("body").html("<p>works awfully!</p>");
You declared “Var” with capital V on this line:
Also, access array’s elements with [index], instead of .get(index)
Here is edited code: