Advice Generator
Hey everyone!
I’m posting here my Mixed Message Project.
I think the project was quite easy to make, but I have knowledge of other languages.
Here is my repository:
Mixed Message - Advice Generator
Thank you, Codecademy team, for this project!
2 Likes
Great one there man.
I think for shorter code you really don’t need the randomMessage
function. you can directly log the random elements of the variables.
//Message Generator
//Arrays with the possible sentences pieces
const introString = ['I think', 'I calculate that', 'I saw in my dreams that', 'A little bird told me that', 'My virtual cards said'];
const firstString = ['you should', 'it\'d be good if you could', 'you should not', 'you have to', 'you absolutely can\'t'];
const secondString = ['trust', 'forget about', 'love', 'ignore', 'be friends with', 'work hard for', 'enjoy', 'have fun with'];
const thirdString = ['anyone', 'everything', 'your heart', 'your job', 'your head', 'your family', 'nature'];
//This function uses a random number as the index to select and return one of the sentences pieces inside the array.
const selectRandomString = arr => {
const randNum = Math.floor(Math.random() * arr.length);
return arr[randNum];
}
//Printing the final result
console.log(`${selectRandomString(introString)} ${selectRandomString(firstString)} ${selectRandomString(secondString)} ${selectRandomString(thirdString)}`);
Thanks for the tip! I’ll keep that in mind for the future