I tried many times but the code doesn’t work and gives no output
Attached below is an image in which I’ve written my code in Sublime(left)
and the same code wrriten by the tutor in the right hand side
I tried referring to the code written by others here and still cannot find the real problem here
<p id="output">Default Text</p>
<input id="user_number">
<button onclick="update_user()">Submit</button>
<script type="text/javascript">
function update_user(){
user_number = document.getElementById("user_number").value;
httpRequest = new XMLHttpRequest();
httpRequest.open("GET", "https://reqres.in/api/users/"+user_number);
httpRequest.send();
httpRequest.onreadystatechange = function(){
if (this.readystate == 4 && this.status == 200) {
user_data = JSON.parse(this.responseText);
document.getElementById("output").innerHTML = user_data.data.first_name;
}
}
}
</script>