chrisgarvey
Technical User
I have the following very simple program, shown below.
I am a newbe to HTML.
I am trying change the below so after the user has entered anything into the command prompt & pressed enter. It automatically refreshes the page with an command prompt.
Any help would be much appreciated.
Chris
<HTML>
<HEAD>
<TITLE>Double it</TITLE>
</HEAD>
<BODY>
<H1>Doubller</H1>
<script language="JavaScript">
//ask the use for a number and try to convert the input into a number
var userNumber = Number(prompt("Enter a number between 1 and 10",""
);
//if the value of userNumber is NaN then ask the user to try again
if (isNaN(userNumber))
{
document.write("Please ensure a valid number is entered"
;
}
//if the value is a number but over 10 then ask the user to try again
else
{
if (userNumber > 10 || userNumber < 1)
{
document.write("The number you entered is not between 1 and 10"
;
}
//otherwise the number is between 1 and 10 so write to the screen
else
{
document.write("The number you entered was " + userNumber);
document.write("<br />"
;
document.write("The number doublled is " + userNumber * '2');
}
}
</script>
</BODY>
</HTML>
I am a newbe to HTML.
I am trying change the below so after the user has entered anything into the command prompt & pressed enter. It automatically refreshes the page with an command prompt.
Any help would be much appreciated.
Chris
<HTML>
<HEAD>
<TITLE>Double it</TITLE>
</HEAD>
<BODY>
<H1>Doubller</H1>
<script language="JavaScript">
//ask the use for a number and try to convert the input into a number
var userNumber = Number(prompt("Enter a number between 1 and 10",""
//if the value of userNumber is NaN then ask the user to try again
if (isNaN(userNumber))
{
document.write("Please ensure a valid number is entered"
}
//if the value is a number but over 10 then ask the user to try again
else
{
if (userNumber > 10 || userNumber < 1)
{
document.write("The number you entered is not between 1 and 10"
}
//otherwise the number is between 1 and 10 so write to the screen
else
{
document.write("The number you entered was " + userNumber);
document.write("<br />"
document.write("The number doublled is " + userNumber * '2');
}
}
</script>
</BODY>
</HTML>