我是JavaScript的新手,正在尝试这个练习:
制作两个版本的随机侮辱发生器:一个 使用+运算符创建字符串,并创建一个字符串 一个数组,并用“”连接。
我用这种方式做的第一台发电机但是如何做第二台呢?
var randomBodyParts = ["Face", "Nose", "Hair"];
var randomAdjectives = ["Smelly", "Boring", "Stupid"];
var randomWords = ["Fly", "Marmot", "Stick", "Monkey", "Rat"];
var randomAnimalBodyParts = ["Tail", "Feelers", "Wings", "Trunk"];
var randomBodyPart = randomBodyParts[Math.floor(Math.random() * 3)];
var randomAdjective = randomAdjectives[Math.floor(Math.random() * 3)];
var randomWord = randomWords[Math.floor(Math.random() * randomWords.length)];
var randomAnimalBodyPart = randomAnimalBodyParts[Math.floor(Math.random() * randomAnimalBodyParts.length)];
var randomInsult = "Your " + randomBodyPart + " is more " + randomAdjective + " than a " + randomWord + "’s" + " " + randomAnimalBodyPart + ".";
randomInsult;
"Your Face is more Boring than a Rat’s Tail."