I wrote the code so that when entering two numbers he compared them and said which number is greater or they are equal, but the text with the result is not displayed.
What is the problem?

JS code:

function compNumb() var a,b,d; a = document.getElementById("i1").value; a = parseInt(a); b = document.getElementById("i2").value; b = parseInt(b); d = document.getElementById("out") if (a>b) { document.getElementById("out").innerHTML = "Первое число больше второго!"; } else if (a<b) { document.getElementById("out").innerHTML = "Второе число больше."; } else { document.getElementById("out").innerHTML = "Числа одинаковы."; } 

html code:

  <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="1.js" defer></script> </head> <body> <p>Введите числа для сравнения! <input type="text" id="i1"></p> <p><input type="text" id="i2"></p> <p id="out">ТУТ</p> <hr> <button onclick="compNumb()">Сверяю</button> </body> </html> 
  • one
    The code is usually given in the question, and not to make a link to external resources. It is more convenient - no need to go anywhere, besides there is no risk that the link will become invalid over time. - aa_talanin 1:09 pm
  • I will consider What about the question, what's the problem? - Danya Brandt
  • @DanyaBrandt regarding the issue: the problem is that your code is not in it - questionable is to edit - Igor
  • Corrected. What's next? - Danya Brandt
  • First fix the syntax errors - E_K

1 answer 1

You have an error in the syntax, there are no brackets.

 function compNumb() { //скобка var a, b, d; a = document.getElementById("i1").value; a = parseInt(a); b = document.getElementById("i2").value; b = parseInt(b); d = document.getElementById("out"); if (a>b) { document.getElementById("out").innerHTML="Первое число больше второго!"; } else if (a<b) { document.getElementById("out").innerHTML="Второе число больше."; } else { document.getElementById("out").innerHTML="Числа одинаковы."; } }//скобка 
 <p>Введите числа для сравнения! <input type="text" id="i1"></p> <p><input type="text" id="i2"></p> <p id="out">ТУТ</p> <hr> <button onclick="compNumb()">Сверяю</button>