I have a problem where I’m trying to generate insults, or just use this as the base for a game and other projects, but when I hit the generate insult button, it doesn’t do anything.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Unfiltered Insult Generator</title>
<style>
fieldset {
margin-bottom: 1em;
}
legend {
font-weight: bold;
}
.language-select {
display: inline-block;
}
.language-select ol {
list-style-type: none;
padding: 1;
}
.language-select label {
display: block;
}
.language-select input[type="checkbox"] {
margin-right: 0.5em;
}
.language-select input[type="text"] {
margin-top: 1em;
}
.srOnly {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;
}
</style>
</head>
<body>
<script>
function getRandom() {
return Math.floor(Math.random() * 100);
}
function generateInsult() {
let name = document.getElementById('name').value;
let num = getRandom();
let insult;
if (num === 99) {
insult = name + " is a lucky ducky! 99, dam!";
id99
} else if (num === 98) {
insult = name + " was so close to success. But I guess you're just a failure in life.";
id98
} else if (num === 97) {
insult = name + " is kinda stupid.";
id97
} else if (num === 96) {
insult ="Hey" + name + "turn it upside down.";
id96
} else if (num === 95) {
insult = num + " is literally the most boring number you could have gotten. Go try again.";
id95
} else if (num === 94) {
insult = "Hey " + name + ", Can I have the name of your hair salon? I need to know where not to go.";
id94
} else if (num === 93) {
insult = name + ", You are the human equivalent of a participation trophy.";
id93
} else if (num === 92) {
insult = name + ", you have a face for radio.";
id92
} else if (num === 91) {
insult = name + ", whatever kind of look you were aiming for, you missed.";
id91
} else if (num === 90) {
insult = name + ", I smell something burning. Are you trying to think again?";
id90
} else if (num === 89) {
insult = name + ", you’re like a lighthouse in a desert: bright but not very useful.";
id89
} else if (num === 88) {
insult = name + ", you’re as useless as the “ueue” in “queue!";
id88
} else if (num === 87) {
insult = name + ", whatever is eating you must be suffering terribly.";
id87
} else if (num === 86) {
insult = name + ", if you ever had a thought, it would die of loneliness.";
id86
} else if (num === 85) {
insult = name + ", this is why the gene pool needs a lifeguard.";
id85
} else if (num === 84) {
insult = name + ", you have the charisma of a wet sock.";
id84
} else if (num === 83) {
insult = name + ", I don’t understand, but I also don’t care, so it works out nicely.";
id83
} else if (num === 82) {
insult = name + ", I’ve seen salad that dresses better than you.";
id82
} else if (num === 81) {
insult = name + ", You have the communication skills of an alarm clock.";
id81
} else if (num === 80) {
insult = name + ", honestly, I'm just impressed you could read this.";
id80
} else if (num === 79) {
insult = name + ", no I'm not insulting you, I'm describing you.";
id79
} else if (num === 78){
insult = name + ", your birth certificate is an apology letter from the condom factory.";
id78
} else if (num === 77){
insult = name + ", the only way you'll ever get laid is if you crawl up a chicken's ass and wait.";
id77
} else if (num === 76) {
insult = name + ", my psychiatrist told me I was crazy and I said I want a second opinion. He said okay, you're ugly too.";
id76
} else if (num === 75) {
insult = name + ", you must have been born on a highway because that's where most accidents happen.";
id75
} else if (num === 74) {
insult = name + ", brains aren't everything. In your case they're nothing.";
id74
} else if (num === 73) {
insult = name + ", some babies were dropped on their heads but you were clearly thrown at a wall.";
id73
} else if (num === 72) {
insult = name + ", you can walk, but can you talk?";
id72
} else if (num === 71) {
insult = name + ", I'd slap you, but that would be animal abuse.";
id71
} else if (num === 70) {
insult = name + ", stop trying to be a smart ass, you're just an ass.";
id70
} else if (num === 69) {
insult = "Damn, you just got the best number!";
id69
} else if (num === 68) {
insult = "One off, get better at life.";
id68
} else if (num === 67) {
insult = "Why was six scared of seven? Because seven ate nine!";
id67
} else if (num === 66) {
insult = name + ", why don't you slip into something more comfortable... like a coma.";
id66
} else if (num === 65) {
insult = name + ", you get ten times more girls than me? ten times zero is zero...";
id65
} else if (num === 64) {
insult = name + ", You're so fat, you could sell shade."
id64
} else if (num === 63) {
insult = name + ", have you been shopping lately? They're selling lives, you should go get one.";
id63
} else if (num === 62) {
insult = name + ", I don't think you understand the concept of 'no eating'.";
id62
} else if (num === 61) {
insult = name + ", that's one small step for me, and a massive one for you.";
id61
} else if (num === 60) {
insult = name + ", I'd like to see things from your point of view but I can't seem to get my head that far up my ass.";
id60
} else if (num === 59) {
insult = name + ", every time I'm next to you, I get a fierce desire to be alone.";
id59
} else if (num === 58) {
insult = name + ", why do you always wear black? Do you like looking like a clown?";
id58
} else if (num === 57) {
insult = name + ", you're so dumb that you got hit by a parked car.";
id57
} else if (num === 56) {
insult = name + ", how did you get here? Did someone leave your cage open?";
id56
} else if (num === 55) {
insult = name + ", I didn’t ask for your opinion.";
id55
} else if (num === 54) {
insult = name + ", pardon me, but you've obviously mistaken me for someone who gives a damn.";
id54
} else if (num === 53) {
insult = name + ", don't you have a terribly empty feeling - in your skull";
id53
} else if (num === 52) {
insult = name + ", as an outsider, what do you think of the human race?";
id52
} else if (num === 51) {
insult = name + ", I have neither the time nor the crayons to explain this to you.";
id51
} else if (num === 50) {
insult = name + ", I would agree with you but then we would both be wrong.";
id50
} else if (num === 49) {
insult = name + ", you're so dense, light bends around you.";
id49
} else if (num === 48) {
insult = name + ", you're as useful as a waterproof teabag.";
id48
} else if (num === 47) {
insult = name + ", you're so clumsy, you could trip over a wireless network.";
id47
} else if (num === 46) {
insult = ", you're so slow, you make sloths look like Olympic sprinters.";
id46
} else if (num === 45) {
insult = name + ", you're not completely useless; you can always serve as a bad example.";
id45
} else if (num === 44) {
insult = name + ", you're so gullible, I could sell you air and you'd buy it.";
id44
} else if (num === 43) {
insult = name + ", your family tree must be a cactus, because everyone on it is a prick.";
id43
} else if (num === 42) {
insult = name + ", you're not just a clown; you're the entire circus.";
id42
} else if (num === 41) {
insult = name + ", your agility is comparable to a turtle on a trampoline.";
id41
} else if (num === 40) {
insult = name + ", you have the problem-solving skills of a confused penguin in a desert";
id40
} else if (num === 39) {
insult = name + ", you look like you were drawn with my left hand";
id39
} else if (num === 38) {
insult = name + ", I do not consider you a vulture. I consider you something a vulture would eat."
id38
} else if (num === 37) {
insult = name + ", what do you think of that, Mr. Pajama-Wearing, Basket-Face, Slipper-Wielding, Clipe-Dreep-Bauchle, Gether-Uping-Blate-Maw, Bleathering, Gomeril, Jessie, Oaf-Looking, Stauner, Nyaff, Plookie, Shan, Milk-Drinking, Soy-Faced Shilpit, Mim-Moothed, Sniveling, Worm-Eyed, Hotten-Blaugh, Vile-Stoochie, Callie-Breek-Tattie?";
id37
} else if (num === 36) {
insult = "Your mother was a broken down tub of junk with more gentlemen callers than the operator.";
id36
} else if (num === 35) {
insult = "White people are just untitled word documents.";
id35
} else if (num === 34) {
insult = "Mirrors can't talk. Lucky for you, they can't laugh either.";
id34
} else if (num === 33) {
insult = "Only 1 in 100 people get this on their first try. You aren't lucky. You're just the hundreth person.";
id33
} else if (num === 32) {
insult = "I’ll never forget the first time we met. But I’ll keep trying.";
id32
} else if (num === 31) {
insult = "Here are the first hundred digits of pi! You're welcome: 3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 0628620899 8628034825 3421170679";
id31
} else if (num === 30) {
insult = "Honestly, does " + name + " even appreciate my work?";
id30
} else if (num === 29) {
insult = "The number 29 is fine. But are you?";
id29
} else if (num === 28) {
insult = "Did the mental hospital test too many drugs on you today?";
id28
} else if (num === 27) {
insult = name + ", I thought of you today. It reminded me to take out the trash.";
id27
} else if (num === 26) {
insult = name +", somewhere out there is a tree tirelessly producing oxygen for you. You owe it an apology.";
id26
} else if (num === 25) {
insult = name + ", you just might be why the middle finger was invented in the first place.";
id25
} else if (num === 24) {
insult = name + ", if I had a face like yours, I would sue my parents.";
id24
} else if (num === 23) {
insult = name + ", if I wanted to kill myself, I would climb to your ego and jump to your IQ.";
id23
} else if (num === 22) {
insult = "Phew, I'm getting tired of typing all those insults. Why don't you help me out a little, and tell me your personality so that I can make more.";
id22
} else if (num === 21) {
insult = name + ", don’t be ashamed of who you are. That’s your parent’s job.";
id21
} else if (num === 20) {
insult = name + ", you are proof that evolution can go in reverse.";
id20
} else if (num === 19) {
insult = name + ", Isn’t it dangerous to use your whole vocabulary in one sentence?";
id19
} else if (num === 18) {
insult = name + ", if I had a dollar for every time you said something smart, I’d be broke.";
id18
} else if (num === 17) {
insult = "People clap when they see you. They clap their hands over their eyes.";
id17
} else if (num === 16) {
insult = name + ", I bet your parents change the subject when their friends ask about you.";
id16
} else if (num === 15) {
insult = "I find the fact that you’ve lived this long both surprising and disappointing.";
id15
} else if (num === 14) {
insult = "You should carry a plant around with you to replace the oxygen you waste.";
id14
} else if (num === 13) {
insult = "If you were the light at the end of the tunnel, I’d turn back around.";
id13
} else if (num === 12) {
insult = "I don’t know what your problem is, but I’m guessing it’s hard to pronounce.";
id12
} else if (num === 11) {
insult = "You see that door? I want you on the other side of it.";
id11
} else if (num === 10) {
insult = "Final 10, I can see the light. Oh wait, you're on the other side. Back we go!";
id10
} else if (num === 9) {
insult = "You look like a person in their 80's, but you act like someone who's 9.";
id9
} else if (num === 8) {
insult = "If I had a dollar for everytime you said something smart I would be broke.";
id8
} else if (num === 7) {
insult = name + ", may both sides of your pillow be uncomfortably warm.";
id7
} else if (num === 6) {
insult = "This is the most useless number you could have gotten.";
id6
} else if (num <= 5) {
insult = "You had a 5% chance to get this number. Good job!";
id5_1
} else {
return insult;
}
}
</script>
<h1><script>generateInsult(<!----->Insert Name Here</!------>)</script></h1>
</body>
</html>
I tried multiple different ways, like using getElementId, but it wouldn’t work. I was expecting a header to appear when I push generate insult, but nothing happens. (btw you can use these insults if you want)
2
Answers
Do you mean something like this? JS Fiddle
HTML
Javascript
If you now edit the first heading to your name and click the generate Insult button, a new heading appers with the insult.
But anyway why do you need something like this and what are the ids in each if for? (I just commented them out in case you need them)
You should have used
Array
instead of multipleif else
I’ve used an
Array
of length 5