prompt("Enter your name"); var lifeExpectancy = Math.random() ; lifeExpectancy = Math.floor(lifeExpectancy * 100) + 30; // if (lifeExpectancy > 100){alert(lifeExpectancy + " Years, as old as Dinosaurs")} if (lifeExpectancy <= 100 && > 75 ){ alert(lifeExpectancy + " Years , Many more birthdays to come !!!") } else{ alert(lifeExpectancy + " Years.") }
Shows error on using && and <= operators
Advertisement
Answer
You need to mention the name of variable again for the second comaprison
prompt("Enter your name"); var lifeExpectancy = Math.random() ; lifeExpectancy = Math.floor(lifeExpectancy * 100) + 30; if (lifeExpectancy <= 100 && lifeExpectancy > 75 ){ alert(lifeExpectancy + " Years , Many more birthdays to come !!!") } else{ alert(lifeExpectancy + " Years.") }