Beispiel 1:
let userName = prompt("What's your name?");
if (userName == "Manfred") {
console.log("Hello " + userName + "! You are a godsend!");
} else {
console.log("Hello " + userName + "! You are an ordinary user");
}
Beispiel 2:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS-Demo</title>
</head>
<body>
<script>
age = Number(prompt("Wie alt bist Du?"));
if (age < 18) {
alert("Sorry, no entry!");
} else {
alert("Hello, you are welcome!");
}
</script>
</body>
</html>