+ 1

java script

hello everyone! i want my result open below my box but my result show in new page anybody know that what is it problem? <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> body { background-color: gray ; } div { text-align: center ; } </style> </head> <body> <div> <h2> if you want to know your quality number write your grade </h2> <input type="number" value="number" id="grade" /> <input type="button" value="check!" onclick="age()" /> <br /> <h3>massage:</h3> quality number is:<p id="massage"></p> </div> </body> <script> var lbl = document.getElementById("massage"); function age() { var grade = parseInt(document.getElementById('grade').value); if (grade >= 17 && 20 >= grade) { lbl.innerHTML = document.write('good') } else if (grade > 13 && grade < 17) { lbl.innerHTML = document.write('not bad') } else if (grade > 20) { lbl.innerHTML = document.write('please write your true number') } else { lbl.innerHTML = document.write('bad') } } </script> </html>

3rd Dec 2018, 2:22 PM
Alireza Babaei
Alireza Babaei - avatar
1 ответ
+ 3
don't use document.write() as it will delete the existing HTML and writes new one do something as follows: lbl.innerHTML = "good"; lbl.innerHTML = ""not bad"; etc
3rd Dec 2018, 3:00 PM
Rishi Anand
Rishi Anand - avatar