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");
3 odpowiedzi
+ 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");
}
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");
}
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)