Измените условие if на условие ниже
if (realName == "Alex" || realName == "alex" || realName == "Alexander" ||realName == "alexander")
Используйте .value
, чтобы получить значение из поля ввода.Без него вы получите весь элемент ввода
let randomNicknames = [
"Noob",
"Doge",
"Roblox Bully",
"Mama",
"Doodle"
];
let randomNicknames2 = [
"Ironman",
"Howard the Alien",
"Roblox rich kid",
"Moto Moto",
"Muhammad the 2nd"
];
function generate() {
let realName = document.getElementById("name").value;
if (realName == "Alex" || realName == "alex" || realName == "Alexander" ||realName == "alexander") {
document.getElementById("demo").innerHTML = randomNicknames[Math.floor(Math.random() * randomNicknames.length)];
} else {
document.getElementById("demo").innerHTML = randomNicknames2[Math.floor(Math.random() * randomNicknames2.length)];
}
}
p {
font-size: 20px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<script src="main.js"></script>
<title>Nickname Generator</title>
</head>
<body>
Add your first name: <input type="text" id="name" autocomplete="off">
<button onclick="generate()">Generate!</button>
<br>
<br>
Your nickname: <p id="demo"></p>
</body>
</html>