JavaScript Treehouse Club - MASH MASH - JavaScript Stuff You Can Change

Adam Hirschovits
Adam Hirschovits
4,983 Points

The var mashes - why are they pre-selected?

Hi all

Apologies if this is a stupid question (I am a 33 year old learning all this from scratch so way behind the curve) but in the var mash in the function "mash_choice", why have there been entered four types of properties? What is the aim of it in the code, given that people can type in whatever they want?

Best Adam

jack AM
jack AM
2,618 Points

Hey Adam,

No worries, hope we can figure this out... So if you notice the very last word, as it tells your fortune, uses those strings in the variable mash. It randomly selects one of either, 'shack', 'mansion', 'house', or 'apartment', and displays it as the last word, no matter what input the user types in. For instance, if you were to run the app and without typing anything in, keep hitting the "Tell my fortune" button, you'll see the very last word in the fortune being told is changing, leaving "undefined" in place where the user's input WOULD be.

1 Answer

Adam Hirschovits
Adam Hirschovits
4,983 Points

Jack AM - thank you very much indeed! As it happens, the game wasn't working at all for me. However, on going through the code, I noticed that somehow (very confident this was my c*ck-up!) the html didn't link to the JavaScript, so when I added in the link, and played the game, your answer made perfect sense - so very much appreciated for getting back to me on this one!

Best Adam

jack AM
jack AM
2,618 Points

Yep that'll do it haha. Glad it worked out, happy coding!