Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 2
No, it has to be written like this
if (x == "one" || x == "two") {
document.write("hello")
}
Otherwise, it will always print hello no matter what because the string "two" is a truthy value.
+ 1
The syntax is valid, but the logic is not.
As-is the block of code will execute no matter what x is equal to.
Even if you change the strings to integers the logic is still the same.
As-is the conditional statement reads [if x is equal to "one" is true or "two" is true, then print hello to the document], a non-empty string is always true.
In order to get the code to perform as expected, you need the know if x is equal to "one" or is x is equal to "two".
https://code.sololearn.com/W21qURYF60Ch/#js
0
if you want x to be equal to the string values 'one' or 'two', then yes.
However, if you want x to be equal to numeric values 1 or 2, then replace 'one' and 'two' with 1 and 2.