chrisgarvey
Technical User
Hello,
I am trying to practice my skills as i am a beginner.
I have wrote the following program below to double a number.
I am now trying to create a while loop with a sentinel value.
When the user types eof, i am trying to get the program to stop prompting to enter a number and instead display program ended.
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",""
);
//sentinel value of eof to terminate loop
while (value != eof);
{
//if the value of userNumber is NaN then ask the user to try again
if (isNaN(userNumber))
{
alert("Please ensure a valid number is entered"
;
window.location.reload();
}
//if the value is a number but over 10 then ask the user to try again
else
{
if (userNumber > 10 || userNumber < 1)
{
alert ("The number you entered is not between 1 and 10"
;
window.location.reload();
}
//otherwise the number is between 1 and 10 so write to the screen
else
{
alert("The number you entered was " + userNumber);
alert("The number doublled is " + userNumber * '2');
window.location.reload();
}
}
}
//loop ended print program ended
document.write("program ended"
;
</script>
</BODY>
</HTML>
I am trying to practice my skills as i am a beginner.
I have wrote the following program below to double a number.
I am now trying to create a while loop with a sentinel value.
When the user types eof, i am trying to get the program to stop prompting to enter a number and instead display program ended.
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",""
//sentinel value of eof to terminate loop
while (value != eof);
{
//if the value of userNumber is NaN then ask the user to try again
if (isNaN(userNumber))
{
alert("Please ensure a valid number is entered"
window.location.reload();
}
//if the value is a number but over 10 then ask the user to try again
else
{
if (userNumber > 10 || userNumber < 1)
{
alert ("The number you entered is not between 1 and 10"
window.location.reload();
}
//otherwise the number is between 1 and 10 so write to the screen
else
{
alert("The number you entered was " + userNumber);
alert("The number doublled is " + userNumber * '2');
window.location.reload();
}
}
}
//loop ended print program ended
document.write("program ended"
</script>
</BODY>
</HTML>