Post Climb Postcard explainer

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.'
]);

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

Could you share a screenshot of your code?

–Frankie

I have the same issue

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

I am having issues. I press the green button, and nothing happens. I don’t believe I have nesting if statements

1 Like

I am having the same issue. My code looks the same but I am just getting spinning wheels in the “example solution” and “your solution” boxes.

1 Like

Hey there, this happens when the webview that powers the Example Solution and Your Solution either downloads too slowly or fails to download altogether. This can occur on slow or interrupted internet connections. Refreshing the page will restart the download and should fix the issue.

Hope this helps!
Ben

I am having the same issue posted above. (example solution and your solution sections stuck on loading) I don’t think it’s an issue with my internet connection as I breezed through the entire first fundamentals course.

I was able to get past this lesson by using Firefox as opposed to Chrome. You may want to check into that test’s compatibility with Chrome.

1 Like

Same issue here, compiler windows aren’t working, even on refresh.

1 Like

I have chrome. This same prob. Is occurring for me.

I can’t figure out how to fix it!!

Hey there,

It’s hard to say if switching browsers fixed the issue, or if your connection improved in the time it took to switch to another browser. In any case, I’m glad to hear that you were able to get past the problem!

Ben

This is the same exact issue I’ve been having. I would really like to continue with the lessons, but the loading screens won’t load, and I’m stuck. Literally!!!

I don’t think switching browsers will help. It just keeps spinning, and it refuses to move on to the next lesson. I want to be able to move on!!!

Can I also replace the second “if” with else?

You could, although it would be slightly different, as it would also run if message.length === 80.

Hello I prepared to code but I can’t run it?

Hey there, try refreshing the page. That should solve the problem.

Hope this helps!
Ben

1 Like