Open The Lock explainer

This stage is very basic and understandable. Typically I wouldn’t be here, but on my Samsung Galaxy Note 8, after I set up -

if (foundKey === ‘no’)

I am unable to click after ‘no’ and add the && to check for the pinNumber. Everytime I click string and type no, click done and then click the && button, it then adds parenthesis in the statement, which makes sense… but there’s no seeable option to complete this stage for me.
plz fix

Hey @Rex,

I responded on the explainer thread, but linking here too incase you don’t see it.

Thanks for flagging this feedback,
H :slight_smile:

I am having a problem to solve it. It is continuous telling me that I have deleted some statements. I have done what is suggested but still stack in the same problem.
If (founder === (‘no’ && pinNimber === print (‘you don’t found the key’))
}

Hi @Sambizus,

  1. You have three ( and two ); they must be paired.

  2. === is used to compare two things. You have pinNumber on the left of a === and a command, print, on the right.

It still doesn’t resolve my problem.

Hi @Sambizus,

This was a small bug on our side with the && and || operators: if you tried to enter them with only the last part of an expression selected (such as only 'no' selected, rather than founder === 'no'), the parentheses are applied like the example you shared.

We’ve fixed this now, so if you update the app and try adding && or || again we won’t place them within parentheses. To solve the Open The Lock puzzle, you can also reset the code, and then edit the value; you don’t need to add in && or || — which may have been why you were seeing warnings about some statements being removed.

Hope this helps a little!
H :slight_smile:

oooh I found a typo in this one. (Thanks to my newfound code knowledge. And my eyes ;). I’ll let y’all spot this one!

Help me!

2 Likes

Hey there, post a screenshot of your code and I can take a look.

-Ben

Seems like a very confusing way to go about trying to help new students that are looking at example code to familiarize themselves with how code is written. var should be declared to avoid other types of confusion, like, how is it possible that you can have print statement before the if statement. So wrong on so many levels. Seems kind of a trap and recipe for confusion and frustration.

hey I am struggling to solve this, it keeps telling me

he starter code has been edited or removed. Use the reset button to reset the puzzle.

and I have only edited the second if statement

1 Like

Hey there, post a screenshot and I’ll take a look.

Ben

I agree that hiding the code is VERY confusing. I experienced this same confusion with the “Bake a Cake” puzzle. I had no idea what the function cook () is supposed to do. Please find a way to let us know when there is hidden code and give us the option to view the code. Perhaps include a toggle button that lets us toggle the hidden code off and on.

Thank you for offering these lessons. Overall, I am so thankful and pleased that you are offering them to us for free. They are so helpful!

1 Like

What is the difference between both the if statements…
I didn’t get that. Both are having same conditions yet they both print different print statements

var foundKey = pickRandom (['yes','no']); //additional information
var pinNumber = 10;
print('pinNumber is ' + pinNumber);
print('foundKey is ' + foundKey);
if (foundKey === 'yes' && pinNumber === 10) {
  print('You opened the lock!');
}
if (foundKey === 'yes' && pinNumber === 10) {
  print('The pin number is right, but you are missing the key.');
}
  1. What does && actually do? I understand that it’s combining but what does that mean? How is this ‘and’ operator different from “+” for instance?
  2. How do you say && when reading it out aloud?
  3. In the puzzle they mentioned “checks” as things, not an action, and suddenly I’m confused. Are tests and checks the same?

Hey there, + means “plus”, while && means “and”. + is a math operator used to add 2 numbers together or concatenate strings (meaning appending one string to the end of another string).

&& is a logical operator. If both values to the left and right of && are true, then the && returns true. Similar to this is the || “or” operator. If one or both of the values to left and right of the || are true, then || returns true. Like this:

var looksLikeADuck = true;
var swimsLikeADuck = true;
var quacksLikeADuck = true;

if (looksLikeADuck && swimsLikeADuck && quacksLikeADuck) {
  print('This might be a duck')
}
// all of these values are true, so the if statement will run

// Here's an example with the or operator ||
var weather = 'raining'

if (weather === 'raining' || weather === 'snowing') {
    print('Put boots on')
}
// weather === 'raining' is true
// weather === 'snowing' is false
// The if statement will run because one value is true

As for your last question, test and check mean the same thing for the purposes of these lessons.

Hope this helps!
Ben

1 Like

Post a screenshot of your code so that we can guide you to the solution.

not helping!!! it says the starter code have been removed or changed
ues the reset button to reset puzzel

I got a question I entered this code and I got it correct? Why?

print

(

'pinNumber is ’

pinNumber

)

;

print

(

'foundKey is ’

foundKey

)

;

if

(

foundKey

===

‘yes’

&&

pinNumber

===

10

)

{

print

(

‘You opened the lock!’

)

;

}

if

(

foundKey

===

‘no’

&&

pinNumber

===

10

)

{

print

(

‘The pin number is right, but you are missing the key.’

)

;

}