Uncaught TypeError: Cannot set property 'innerHTML' of null
var questions = [ 'hi', 'fyn', 'Thank u' ]; var num == 0; var output = document.querySelector("#Student"); output.innerHTML = questions[0]; var inputBox = document.querySelector("#ans"); function showResponse(){ var input = inputBox.value; if(inputBox.value == "") { } else { if(num == 0) { output.innerHTML = '${ans} hi'; inputBox.value = ""; ++num; setTimeout(changeQuestion, 2000); } else if(num == 1) { output.innerHTML = '${ans} fyn'; inputBox.value = ""; ++num; setTimeout(changeQuestion, 2000); } } } function changeQuestion(){ output.innerHTML = questions[num]; if(num == 2) { inputBox.style.display = "none"; } } $(document).on('keypress', function(e) { if(e.which == 13){ showResponse(); } })