무작위 모욕 발생기를 작성했습니다. 그것은 좋고, 내가 필요한 것에 잘 맞습니다. 문제는 모든 vars를 다시 복사하지 않으면 프로그램이 두 번 이상 실행될 때마다 모욕이 항상 동일하다는 것입니다. 내가 할 노력하고있어랜덤 모욕 발생기 (랜덤 화 결과)
var bodyPart = ["face", "foot", "nose", "hand", "head"];
var adjective = ["hairy and", "extremely", "insultingly", "astonishingly"];
var adjectiveTwo = ["stupid", "gigantic", "fat", "horrid", "scary"];
var animal = ["baboon", "sasquatch", "sloth", "naked cat", "warthog"];
var bodyPart = bodyPart[Math.floor(Math.random() * 5)];
var adjective = adjective[Math.floor(Math.random() * 4)];
var adjectiveTwo = adjectiveTwo[Math.floor(Math.random() * 5)];
var animal = animal[Math.floor(Math.random() * 5)];
var randomInsult = "Your" + " " + bodyPart + " " + "is more" + " " + adjective + " " + adjectiveTwo + " " + "than a" + " " + animal + "'s" + " " + bodyPart + ".";
randomInsult;
"Your nose is more insultingly stupid than a warthog's nose."
randomInsult;
"Your nose is more insultingly stupid than a warthog's nose."
내가 다시 randomInsult;
를 실행할 때, 나는 다른 결과를 원하는 것입니다 : 여기 내 코드입니다.
:
이 방법을 호출합니다. 모든 일은 변수를 한 번 선택하여 할당하는 것입니다. 당신의 기능은 임의의 모욕을 다시 고를 것입니다. 게다가 어레이의 단일 결과를 할당 할 때 실제로 배열 변수를 덮어 쓰고 있습니다. – TommyBs