I'm trying to write this exercise from a book:
Write a program to ask yourself, using prompt, what the value of 2 + 2 is. If the answer is "4", use alert to say something praising. If it is "3" or "5", say "Almost!". In other cases, say something mean.
I made this attempt:
var input = "" || 'number'
prompt ("How many is 2+2 ?", input)
if (input = 4)
print ("Awesome !");
else if (input = 3 || input = 5)
print ("Close !");
else if (input = 'number'
print ("wrong number");
else if (input = 'random text')
print ("use numbers only!")
I know it is wrong. This is I intended to do:
I need to determine the type of
var, not just the value. I need to makevareither number or string (according totypeof). Why ? Forpromptimput, because belowelse ifcondition, will be based on which type was inputted.I know that exercise didn't asked it, but I want make it superior.
==to test if something is equal to something else, not=.===;)promptinput is always a string. Do you meantypeofsomething else?