Tuesday, May 14, 2024
155
rated 0 times [  158] [ 3]  / answers: 1 / hits: 128586  / 7 Years ago, sat, february 18, 2017, 12:00:00

I'm having trouble recalling how to compare these two strings in an if statement. What I'm string to do is check if my variable compare equals page1 or page2 if not, go to the else statement.





var compare = page3;

if (compare === page1 || page2) {
document.body.innerHTML = github url;
} else {
document.body.innerHTML = non-github url;
}




More From » if-statement

 Answers
20

Try



if( [page1, page2].includes(compare) ){...}




var compare = page3;

if( [page1, page2].includes(compare) ) {
document.body.innerHTML = github url;
} else {
document.body.innerHTML = non-github url;
}




[#58881] Thursday, February 16, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amari

Total Points: 736
Total Questions: 111
Total Answers: 90

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;