运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <p>I'm thinking of a letter. Guess which: a, b, c, d or e?</p> <input id="myInput" type="text"> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var letter = document.getElementById("myInput").value; var text; // If the letter is "c" if (letter === "c") { text = "Spot on! Good job!"; // If the letter is "b" or "d" } else if (letter === "b" || letter === "d") { text = "Close, but not close enough."; // If the letter is anything else } else { text = "Waaay off.."; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>