0

I am getting an error on the second output.

var compareNumber = 3; // Code will be tested with: 3, 8, 42
var userNumber = '3'; // Code will be tested with: '3' 8, 'Hi'

/* Your Response goes Here*/

if (userNumber == compareNumber) {
  console.log('Numbers are equal\nVariables are not identical');
} else {
  console.log('Variables are not identical');
}

Error Image

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Dani
  • 1
  • 3
  • you have an extra opening curly braces **{** at the end of console – Sameer Jan 27 '20 at 06:21
  • It was a typo. I corrected – Dani Jan 27 '20 at 06:23
  • This doesn't make sense though. When `compareNumber` and `userNumber` will both be `8`, they will be equal AND identical, aren't you theoretically missing an `else if` with a `===` operator? – Mike K Jan 27 '20 at 06:24

1 Answers1

1

Please check this out for your solution.

In javascript == checks for the values only without type, so 3 & '3' are same for this as the value is same, although type is different, so this will return true

=== matches both value & type both, so 3 & '3' are different here, it will return false

var compareNumber = 8; // Code will be tested with: 3, 8, 42
var userNumber = 8; // Code will be tested with: '3' 8, 'Hi'

/* Your Response goes Here*/

if (userNumber === compareNumber) {
  console.log('Numbers are identical');
} else if(userNumber == compareNumber){
  console.log('Numbers are equal\nVariables are not identical');
} else {
  console.log('Variables are not identical');
}
Mike K
  • 7,621
  • 14
  • 60
  • 120
Sarfraaz
  • 1,273
  • 4
  • 15