I thought it was pretty easy, but after reading the example solution realized how I over simplified it. Please tell me why this is might not be a good idea?
https://gist.github.com/ahmad-s-soliman/72e148cc7107f4914bfd78e23ef28b2e
1 Like
Hi @ahmadsoliman, I reviewed your code, it is not over simplified in my opinion, my only suggestion would be to add a maybe a conditional statement to avoid getting “bad luck” and “be happy” on the same message.
Nice work, have a great one.
Hey @ahmadsoliman .
I had almost the same solution and thought I’d play around with it a bit and review the class syntax again, although I probably could have achieved the same with a regular function.
Here is my solution know, please let me know what do you think about it 
regards
Robin
class MixedMessages {
constructor(sentenceParts) {
this.sentenceParts = sentenceParts;
}
getRdmText(array){
const randomIndex = Math.floor(Math.random() * array.length);
return array[randomIndex];
}
get rdmMessage(){
let message= [];
for (const key in this.sentenceParts) {
if (this.sentenceParts.hasOwnProperty(key)) {
message.push(this.getRdmText(this.sentenceParts[key]))
}
}
return `${message.join(' ')}.`;
}
};
const studentsSentenceParts = {
part1: ["Students", "Scholars", "Researchers", "The education system", "Academics"],
part2: ["are studying", "studied", "will research", "have learned", "explore"],
part3: ["the universe", "historical events", "new scientific theories", "modern literature", "cultural traditions"]
};
const studentsSentence = new MixedMessages(studentsSentenceParts);
let rdmStudentsSentence = studentsSentence.rdmMessage;
console.log(rdmStudentsSentence);
const travelersSentenceParts = {
part1: ["Travelers", "Explorers", "Tourists", "Adventurers", "Backpackers"],
part2: ["are exploring", "explored", "will visit", "have discovered", "travel to"],
part3: ["ancient ruins", "exotic islands", "famous landmarks", "remote villages", "natural wonders"]
};
const travelerSentence = new MixedMessages(travelersSentenceParts);
let rdmTravelerSentence = travelerSentence.rdmMessage;
console.log(rdmTravelerSentence);
PS: I will upload to Github and create ReadMe file tomorrow 