The function is accepting (val) as an argument and if the (val == 5) it should execute if statement and return Equal, otherwise not equal. But if val is equal to 5 then also function is returning false Not Equal. Beginner Here. Thanks
javascript
function testNotEqual(val) {
if (val == 5) {
return "Equal";
}
else {
return "Not Equal";
}
}
testNotEqual(5);
console.log(testNotEqual());
Try this:
function testNotEqual(val) {
if (val == 5) {
return "Equal";
}
return "Not Equal";
}
let test = testNotEqual(5);
console.log(test);
You invoked this function twice and second time you passed nothing as an argument
function testNotEqual(val) {
if (val === 5) {
return "Equal";
} else {
return "Not Equal";
}
}
document.getElementById("te").innerHTML = testNotEqual(5);
body {
margin: 0;
background: #333;
}
<p style="color:white" >The Result is: <span id="te"></span>
</p>