Hi, I’m new to codecademy and to this forum, yet I’ve covered only 5 chapters of JS.
I’m trying to build an “8 ball ask question” game, and actually it all works (because it’s way too simple).
But anyway, my question is: is it possible to automate (e.g. put in one to several strings of code) the part with “if (eightball < 0.N) {eightball = answers[N];”
Thank you.
Here’s my code:
var answers = ["Yes.", "No.", "I'm not sure.", "Sure!", "No way", "I can't tell you.", "You know the answer", "Don't even think of it", "Of course.", "Sorry, try later."];
var eightball = Math.random();
if (eightball < 0.1) {
eightball = answers[1];
}
else if (eightball < 0.2){
eightball = answers[2];
}
else if (eightball < 0.3){
eightball = answers[3];
}
else if (eightball < 0.4){
eightball = answers[4];
}
else if (eightball < 0.5){
eightball = answers[5];
}
else if (eightball < 0.6){
eightball = answers[6];
}
else if (eightball < 0.7){
eightball = answers[7];
}
else if (eightball < 0.8){
eightball = answers[8];
}
else if (eightball < 0.9){
eightball = answers[9];
}
else if (eightball <= 1){
eightball = answers[10];
};