JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge

Here's my interpretation of the variable challenge. Take a look!

alert ("Want to play a game? Follow the instructions")
let introduction = "Remember, remember the 5th of ";
let nouns = prompt ("Give me: 'November'");
let gunpowderString = ", the gunpowder treason and ";
let verbs = prompt ("Please, give me some 'plot'");
let iKnowString = ". I know of no reason why the gunpowder ";
let adjectives = prompt ("Let's write a 'treason'!");
let endString = " shoud ever be forgot.";
alert("Are you ready for awesome story? #V like Vendetta");
let story = introduction + nouns + gunpowderString + verbs + iKnowString + adjectives + endString + " #the end".toUpperCase();
document.write (story);

2 Answers

Dear Konrad S,

You're good with the solution you've come up with. But instead of let, you should use const. When the value of the variable is not to change, then const should be your choice. In fact, you should first consider using const but when you see that the value needs to change, use let.

alert(`Want to play a game? Follow the instructions`)
const nouns = prompt (`Give me: 'November'`);
const verbs = prompt (`Please, give me some 'plot'`);
const adjectives = prompt (`Let's write a 'treason'!`);
alert(`Are you ready for awesome story? #V like Vendetta`);

const story = `Remember, remember the 5th of ${nouns}, the gunpowder treason and ${verbs}. I know of no reason why the gunpowder ${adjectives}  shoud ever be forgot. ${"#the end".toUpperCase()}`;

And it's always a good idea to move all the variables to the top of the document.
By, the way, I've used string interpolation to get rid of concatenation and unnecessary variables.

Happy Coding !!! :sparkles:

Nafis Fuad

Thank you, for some advice. I like your solution. I will definitely try to use it in practice. ? ?

You're welcome. Happy Learning :smile: