Ternary question


#1

https://www.codecademy.com/courses/learn-javascript-control-flow/lessons/control-flow/exercises/ternary-operator?action=resume_content_item&course_redirect=introduction-to-javascript

Could someone please explain how the initial way does not work. but the ones in the comments do?

This is a bit confusing.


#2

Hi there :slight_smile:

Hopefully, I can clear up a few things.
First, in JavaScript, excessive whitespace is ignored. So whether you used spaces or a new line in the ternary operator, both will work.

Second, your string in the 2nd console.log() is 'I dont love that!' which is missing an apostrophe.
To avoid the single quote confusion, you can use double quotes like in the examples in the forum:
"I don't love that!"

Hope that helps!


#3

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