Javascript Help

User Generated

oynturem

Programming

Description

I am having trouble with the code below because I am trying to call the text field input type so that whenever someone enters a number above 10 it responds with the alert shown below, but I am having a problem because whenever I input a number greater than 10 in the text field it still replies with "the number is less than 10"??? What am I doing wrong? FYI I am a beginner javascript learner 

<script>

//Variables

var txtInput = document.getElementById('txtInput');

//Functions

function submitNum()

{

if (txtInput <= 10)

{

alert("The number is less than 10");

}

else

{

alert("The number is greater than 10");

}

}

</script>

</head>

<body>

<input type="text" placeholder="Type any number" id="txtInput" /><input type="button" onclick="submitNum()" value="Submit" />

</body>

</html>


User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

At least one public class is required in main file


Anonymous
Just the thing I needed, saved me a lot of time.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags