贝壳 - BeiKe 贝壳 - BeiKe - 1 month ago 7
Javascript Question

Why might my Elseif Statement fail?

I believe my elseif is formatted correctly but it is failing. I have tried wrapping the elseif in quotes (second == equal statement), adding extra equal signs. Not sure what else I can do.

if (window.location.href.includes("?") && window.location.href.includes("year=") )
{

console.log("replace the 4 characters following the equal sign");
}

elseif (window.location.href.includes("?") && window.location.href.includes("year=") == "false")
{
console.log("last condition");
}
else {
console.log("end");
}

Answer

In javascript elseif does not exist. Change that by else if.

Something else you'll have to change is

window.location.href.includes("year=") == "false" 

Since includes returns a boolean but I think you're aware of that and it was just a desperate try.