Positive Message Generator

Hello folks, this is my Positive Message Generator in GitHub.

It certainly isn’t perfect so please feel free to be brutally honest :slight_smile:

It functions fine, I would like to know better ways of resetting the code so that I don’t need to refresh the page everytime. And also if there are better ways to do the whole thing, i have been struggling a bit with JS so any help is appreciated.

Thanks :slight_smile:

1 Like

Hey

Loved your project, I laughed at my first one "Hello James, you are the el chungo grandeist, most cute and witty b*****d of all time :)". The only way I know of not having to refresh the page would be to have it so that the function would be called every few seconds? Obviously I am still a newbie so would have to look into how to do something like that.

I thought I'd try and simplify your code, funnily enough I did exactly the same function for someone else, see what you think below. The randomElement function takes an array in its parentheses and returns a random element from that array, also using its length. It just avoids having to repeat a function for each different array.

James


const randomElement = array => {
    return array[Math.floor(Math.random() *array.length)]
}
let positiveMessage = (name) => {   
console.log(`Hello ${name}, you are ${randomElement(prefix)}, ${randomElement(adjective)} and ${randomElement(adjective2)} ${randomElement(descriptor)} of all time :)`)
};

2 Likes