I am trying to put the if else code below into a function:
if (randomnum == 1) {
var codes = ["qjyreu", "achin", "eralnrde", "hiwel", "eW", "ni"];
var words = ["jquery", "china", "learned", "while", "We", "in"];
var finalAnswer = "Welearnedjquerywhileinchina";
} else if (randomnum == 2) {
var codes = ["oegs", "yob", "nignadc", "hTe", "ightn", "veery"];
var words = ["goes", "boy", "dancing", "The", "night", "every"];
var finalAnswer = "Theboygoesdancingeverynight";
}
For reference, the randomnum is defined in the function rando:
function rando() {
return (randomnum = Math.floor(Math.random() * 2) + 1);
}
rando();
Everytime I try and put my if else statement into a function and call it, the console says: codes not defined. I just want to to successfully put my if else statment into a function that I can call.
Aucun commentaire:
Enregistrer un commentaire