For string values, you should use single quote ' ' or the double quotes " ".
Example:
let stopLight = 'green'; //<== Notice the quotation mark? It's not backtick symbol
if (stopLight === 'red') { //<== Same goes for the rest
console.log('Stop'); //<==
} else if (stopLight === 'yellow') {
console.log('Slow down');
} else if (stopLight === 'green') {
console.log('Go!');
} else {
console.log('Caution, unknown!');
}
Change all the backticks into single quote ' ', your code should work.
Code:
let moonPhase=‘full’;
/if(moonPhase===‘full’)
console.log(‘Howl!’);
else
console.log(‘I swear I am not a werewolf.’);/
if(moonPhase===‘full’)
console.log(‘Howl!’);
else if(moonPhase===‘mostly full’)
console.log(‘Arms and legs are getting hairier’);
else if(moonPhase===‘mostly new’)
console.log(‘Back on two feet’);
else
console.log(‘Invalid moon phase’);
This program runs smoothly, but a message "Did you write an else statement that logs ‘Invalid moon phase’?
" is displayed.
Can anyone explain why is this message displayed?