0

If prompt has a certain word inserted, print this

If “Special Name” gets inserted into the naam prompt variable, print the document write. For some reason this doesn’t work and it prints the special text everytime (script language is javascript and sentence language is Dutch) if(naam = "Special Name") { document.write("Dag Special Name, ja je bent een paard"); } else { document.write("nee je bent geen paard");

22nd May 2021, 12:06 PM
Kiriixer
Kiriixer - avatar
3 Respostas
+ 3
//try this var naam = prompt() if(naam == "Special Name") { document.write("Dag Special Name, ja je bent een paard"); } else { document.write("nee je bent geen paard"); }
22nd May 2021, 12:51 PM
Simba
Simba - avatar
0
You are assigning naam the value of "Special Name" The true syntax is this if(naam === "Special Name"){ document.write("Dag Special Name, ja je bent een paard"); } else{ document.write("nee je bent geen paard"); }
22nd May 2021, 1:24 PM
Nima
0
either == or === will both works as expected... difference between them is quite tricky and too long to be deeply explained here. in short: == compare only values and may implicitly cast some operand to other type === compare reference (in case of string, they are immutable types, so it looks like comparing type and value -- without implicit cast)
22nd May 2021, 5:14 PM
visph
visph - avatar