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 Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a `do...while` loop

Alex Forseth
Alex Forseth
8,017 Points

Why would the !== operator be used to determine a password?

Something has been bugging me since I have been stuck on this challenge. Why would you write your code out like this:  

(secret !== "sesame")

in order to confirm that the password is "sesame". Doesn't the !== mean strictly not equal too? If the secret is "strictly not equal" to sesame, how can it be equal to sesame?

I fundamentally do not understand the javascript grammar of this.

Any help would be appreciated.

-Thanks

script.js
var secret = prompt("What is the secret password?");
var count = 0;

do{
  (secret !== "sesame") 
  secret = prompt("What is the secret password?"); 
  document.write("You know the secret password. Welcome.");
}

while (count = secret)
      (count += 1); 
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Christopher De Lette
Christopher De Lette
Courses Plus Student 7,139 Points

Hi Alex,

The !== comparison operator is used in conditional statements to evaluate two variables without coercion. By using the strict operator of !== you are comparing value and type, rather than value. You would not want it to be equals when defining the comparison because if it is the conditional will not run as it equates to true.

Hope this clarifies things.

Take care and Happy Coding!

3 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya there! As Christopher pointed out that , you compare value and type with "===". "==" meas equality in values , whereas "===" means equality in values and data types. So yeah "secret !== sesame" simply implies that , in grammar, if secret is not equal to string sesame. I hope this helped. (:

Ari Misha
Ari Misha
19,323 Points

Hiya there! As Christopher pointed out that , you compare value and type with "===". "==" meas equality in values , whereas "===" means equality in values and data types. So yeah "secret !== sesame" simply implies that , in grammar, if secret is not equal to string sesame. I hope this helped. (:

nico dev
nico dev
20,364 Points

Just an additional comment on the excellent answers already provided. Check it again, there's something in your conversion from a while loop to a do-while one that is not right.

Hint: You don't want to do secret !== sesame. Remember this: the do part is what you want to execute/run, whereas the while is your condition/s to test. :)

Get back to it and try again because you're not far, but just try to use almost the same code but in a different order.

//WHILE:
while (condition) {
    // codeblock that runs
}

//DO->WHILE
do {
    // codeblock that runs
} while (condition)

Hope that clarifies it a bit more?

Alex Forseth
Alex Forseth
8,017 Points

Nico, finnaly was able to understand. Thank for answering though. My main issue I believe is that I fundamentally didn't understand what !== really translated to.

nico dev
nico dev
20,364 Points

Great stuff!!

Keep it up!