Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Javascript notation == early in 'Intro to Programming'

Good Day ya'll!

In the Intro to Programming course/Control Structures/Loops/Fizzbuzz extra credit answers, there is Javascript syntax that I didn't see explained anywhere in the videos to this point or on W3 Schools. See this relevant snippet from another student's code

else if (number % 3 == 0) {
        console.log("fizz");
}

I couldn't get my code to work until I copied "==" (and studied some more) but still cannot surmise the exact meaning. Any explanations please, and where I may reference similar questions?

3 Answers

It just means, if the remaining of the division of the number by 3 is equal to zero, then display fizz, so as an exemple if number was the number 2, fizz wouldn't be displayed, as if you divide 3 by 2, there is a remaining of 1, because in 3 you can just put one time the number 2. While with 3, fizz would be displayed...

ahhh ok. just remembered that using a single '=' tells the program to equate something (i.e. var) to something else (i.e. an input value). it didn't click for me that "==" sets a condition that must be met such as 'check to see if the specified modulo condition "is equal to" ' .

this helped me out. i played around some more in my own script to make sure i understand fully. thanks so much! !

hi stephen,

in programming we use '=' to assign a value, '==' is a comparison operator used to compare a value is same or not to the other value and '===' also a comparison operator but only can be 'true' if both of the conditions that compared have a same value and same data type.

For the "===" comparison operator, you mention "data type" . Do you mean like a string===string might be 'true', but string===number is never 'true' ? What is an example of two different data types? I understand the "same value" part.

yes i mean like that.

example of different data types? numbers, string and booleans(true or false) are different data types.

example:

3 === '3' is false

true === 'true' is false

'treehouse' === 'treehouse' is true

hope it helps :)