Here is the program I built for the Mixed Messages project:
It’s fairly simple - is there anything I could improve?
Here is the program I built for the Mixed Messages project:
It’s fairly simple - is there anything I could improve?
Hi!
Avoid using global variables. For example, the variables jokePt1
, jokePt2
and jokePt3
are used only in the fullJoke
function. So move them inside the function:
// Create a complete joke with a function
const fullJoke = () => {
let jokePt1 = messageArr1[randomNum(messageArr1)];
let jokePt2 = messageArr2[randomNum(messageArr2)];
let jokePt3 = messageArr3[randomNum(messageArr3)];
return `${jokePt1} ${jokePt2}? ${jokePt3}! Haha!`;
};
This will make your code cleaner.
The other thing that you can improve is to introduce funcation that return not a random index for array but random element. So your code let jokePt1 = messageArr1[randomNum(messageArr1)];
will be like that let jokePt1 = randomElement(messageArr1);
. Inside randomElement
you can use existing randomNum
function as a part of it.
Good work!