I’m not sure why I’m not getting an output for my code. It should say “Not Equal”. Where did I go wrong?
Your code so far
// Setup
function compareEquality(a, b) {
if (a === b) { // Change this line
return "Equal";
} else {
return "Not Equal";
}
}
console.log(compareEquality(10, "10"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Challenge Information:
Basic JavaScript - Practice comparing different values
I don’t know why i’m not getting an output and it won’t run.
My code:
// Setup
function compareEquality(a, b) {
if (a === b) { // Change this line
return "Equal";
}
return "Not Equal";
}
console.log(compareEquality(10, "10"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Challenge Information:
Basic JavaScript - Practice comparing different values
Reset the step and try again. If that doesn’t work, refresh the page, disable dark mode, disable ad blockers. Or, use another browser.
If the above steps do not work, you may need to restart the computer.
The reason you’re not getting the expected output “Not Equal” is because the strict equality operator === compares both the value and the type of the operands. In JavaScript, the value 10 and the string "10" are not strictly equal because they have different types.
function compareEquality(a, b) {
if (a == b) { // Using loose equality operator
return “Equal”;
} else {
return “Not Equal”;
}
}
console.log(compareEquality(10, “10”)); // Output: Not Equal
check this code it will work for you. try this and give feedback