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 trialAlex Forseth
8,017 PointsWhy 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
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);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
Ari Misha
19,323 PointsHiya 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
19,323 PointsHiya 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
20,364 PointsJust 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
8,017 PointsNico, 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
20,364 PointsGreat stuff!!
Keep it up!
Christopher De Lette
Courses Plus Student 7,139 PointsChristopher De Lette
Courses Plus Student 7,139 PointsHi 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!