Magic Answers explainer


#1

The aim of this puzzle: Add to the magic 8-ball answers and print out one answer randomly.
Walkthrough of the solution: A list of answers is stored in an array [], to add to the list you’ll need to add a new entry in the array by tapping below the last answer and above the closing bracket - ]. Use the ‘str’ key to type an answer such as 'maybe' or 'outlook good'.
Sample code solution:
(Tap below to reveal)

var answer = pickRandom([
 'yes',
 'no',
 'reply hazy',
 'doubtful',
 'outlook good'
]); 
print(answer);

JavaScript Concepts: Data Structures (Arrays), Variable Declaration, Calling Functions, Identifiers
Grasshopper Concepts: pickRandom(), print()


#2

Magic Answers has me stumped


#3

Hey @Shawn_Soto,

This can be a bit of a tricky puzzle. Do you want to take a screenshot of the code you are trying and I’ll see if I’m able to give you some pointers on how to solve this puzzle?

H :slight_smile:


#4

Is there a video linked to this?


#5

I can’t get passed this at all. I don’t know what I did but I can even access the right stuff on the keyboard after I looked at the answer


#6

@Chris_Troesh Sounds like a possible bug? If you back out and then tap the lesson to open it again, see if it offers you to reset your code or force close the app and reopen it and see if that fixes the issue. If not, see if you can tap the menu in the top right while in the lesson to select ‘Send Feedback’ then ‘Report a Problem’. You can submit screenshots and screen recordings with your report.

@Robot I haven’t seen videos yet, but here are some screenshots of me going through the puzzle to help you compare and follow along.




Then tap the green play button should give you the “Congrats!” popup.

Hope this helps!


#7

I can’t pass it at all. I think the comma at the last of every string can’t be removed and that the problem and after the last string we don’t have to use that comma


#8

Hey @Suraj_Chaudhary,

The extra comma is added by the Grasshopper app to allow for an empty field in all arrays (making it an easy place to tap). This shouldn’t be blocking your progress.

If you’re able to, could you share a screenshot of your code so we can have a look and provide guidance on how to solve this puzzle?

H :slight_smile:


#9

I’m struggling with this. I’ve attached my attempt which has gotten me nowhere. Please help. What am I doing wrong?


#10

It may be worth your time to press the “reset” button on the top row of the keyboard to get back to the starer code.

There are a few things in the code you posted that you would want to change:

  • var positive = pickRandom(positive)
    • This is creating a new variable called positive and assign it a value of pickRandom(positive). This won’t work because pickRandom() only works if you give it an array or a number, and positive is not either of those. In fact, positive doesn’t have any value yet.

After that line, your code will not finish because it can’t get past pickRandom(positive). You won’t have to use an identifier all on its own, like answer; You won’t see any change in your code if you include this or not, so it’s not worth having in there at all.

  • var answer = pickRandom(answer)

    • This has the same problem that the positive declaration had. You’re creating a variable using the variable. This is like trying to define a word using the same word – “An elephant is an animal that is an elephant”, "The variable answer stores a random item from answer", but what exactly is answer storing?
  • ['yes', 'no', 'outlook positive']

    • This array is alright except it isn’t being stored in a variable or used in a function, so it won’t affect the output of your code. This array should be placed inside of a pickRandom() call and the result should be assigned to a variable. The starter code already includes this format.

If you reset your code, you’ll only need to add a 3rd string to the starting array, which you’ve already been able to do.

–Frankie


#11

The walkthrough is incorrect; the final sentence, “You’ll also need to update print() so that it’s printing out an answer, rather than ‘no’”, should be removed, since the initial code already does this.

I also agree with @Suraj_Chaudhary; since the commas are separators, not terminators, I suggest that they be marked, such as with a special color, etc. to indicate that they are contingent upon the new field being filled in. Or, have the interpreter complain about them (this would be more realistic and would get the point across) but continue anyway.


#12

In the walkthrough, change “taping” to “tapping”.

Can I suggest rewording the initial text for the problem? Right now, it says “In this puzzle, you’ll add to an array and generate a random answer. An array is a way to store a list of items using code”.

Suggested text: “In this puzzle, you’ll add to an array. An array is a way to store a list of items using code”.

–Scott.


#13

Hey @Scott_McNay,

Thanks for the suggestions and catching those typos! I’ve updated the explainer text here. We’re reviewing the other feedback for changes within the app.

Thanks again!
H :slight_smile:


#14

I have tried doing the but I can’t get this to work here’s my answer


#15

I don’t know what happen but I went back without changing anything and it worked


#16

We’re working on fixing this bug. It’s rare so it’s difficult to know exactly what’s causing it. If you happen to see it again in the future you should be able to close and reopen the app to get rid of it, like you did here.

–Frankie


#17

Any body with explanation on how to solve this magic answer. I’m tired already, can’t think of words to use again


#18

To solve this puzzle, you can use whatever words you want. As long as the array (the of strings between the brackets []) has at least 3 words.

The first post here contains an example solution if you need ideas of words to use.

–Frankie