Basic JavaScript - Practice comparing different values

Tell us what’s happening:

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

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

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

Welcome to the forum @zara.aijaz1991

Your code passes.

Try removing the console.log

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.

Happy coding

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


there is ‘Not Equal’ in the console

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.