Post Climb Postcard explainer

#1

The aim of this puzzle: Print a message depending on a string’s .length property.

Walkthrough of the solution: The code already has an if statement testing if the message variable’s length is greater than 80.
Start by adding a 2nd if statement on a new line that tests if the message length is less than 80. Place the message variable inside the new if statement’s parentheses. Tap the .length button while message is still highlighted. Then, tap the < button to add the comparison operator followed by the ‘num’ button and enter the number 80.
Now, tap the line between the new if statement’s curly braces {} and tap the print() button. Tap the ‘str’ button and enter the string ‘The message fits on a postcard.’ inside the print().

Sample code solution:
(Tap below to reveal)

print(message);

if (message.length > 80) {
  print('The message is too long for a postcard, better send a letter instead.');
}

if (message.length < 80) {
  print('The message fits on a postcard.');
}

JavaScript Concepts: String Properties, .length, If Statements, Comparison Operators, Identifiers

Grasshopper Concepts: print()

Additional Code (hidden code that runs before the puzzle’s code):

var message = pickRandom([
  'Hello from the top of Code Mountain.  The view is amazing.  My adventure is just beginning, where to next?',
  'Greetings from Code Mountain.',
  'The view is awesome from way up here at the peak. I can see a whole world of code to explore.',
  'Just climbed a mountain of code and I am ready for more.'
]);
0 Likes

#4

I did this but I am not getting the green fire works

0 Likes

#5

Could you share a screenshot of your code?

–Frankie

0 Likes

#6

I have the same issue

0 Likes

#7

You have nested If Statements. That means, the inner If Statement can only run if the outer If Statement runs. Take a close look at where the curly brackets are.

Nested Loops:

if (test1) {
  print('test 1 passed');
  if (test2) {
    print('test 2 passed');
  }
}

Test 1 has to pass in order to do the check for test 2.


Not nested Loops:

if (test1) {
  print('test 1 passed');
}

if (test2) {
  print('test 2 passed');
}

Test 1 will be checked. Then test 2 will be checked separately, no matter what.

–Frankie

0 Likes