General discussion

Locked

Javascript programs

By john.cb1 ·
Does anyone know how to do JavaScript programming, if so can you help me to do these programs

I would be grateful if anyone could do these as soon as posible this is why i have awarde 500 pts to this question

1) This is asking you to input a number between 1 and 20 and it gives you your answer here is some code i have done

<HTML>
<HEAD>
<TITLE> TMA 03 - Question 1
</TITLE>
<SCRIPT Language = Javascript>
/* A student is aked to enter a number between 1 an 20 */
var userNumber;
var yourNumber;
userNumber = window.prompt('please enter a number in the range 1 to 20','');
while (userNumber < 1) && (userNumber >= 20)
{
UserNumber = window.prompt('please re-enter - number should be in range 1 to 20', '')
}
document.write('The user's chosen number was' yourNumber');
document.close()
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
-------------------------------------------------

2) A program that prompts a user to enter 5 numbers which are the number of people entering a exbition. Here is the code i have done so far

<HTML>
<HEAD>
<TITLE> Activity_8.2.5
</TITLE>
<SCRIPT >

/* Program to read in a known number of data items and store them in an array */

var rainArray = new Array (12);

document.write('Array program to read in a known number of data items');
for (var month = 0; month < rainArray.length; month = month + 1)
{
rainArray[month] = window.prompt('Enter rainfall value','')
};
document.write('<BR>' + '<BR>');
document.write('Confirmation of data input' + '<BR>' + '<BR>');

for (var month = 0; month < rainArray.length; month = month + 1)
{
document.write(rainArray[month] + '<BR>')
}

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
Thread display: Collapse - | Expand +

All Comments

Collapse -

by chellaganesh In reply to Javascript programs

Hi,
You are almost done with it exept a few bugs, which I have fixed.
Question 1
<HTML>
<HEAD>
<TITLE> TMA 03 - Question 1 </TITLE>

<SCRIPT Language = Javascript>
/* A student is aked to enter a number between 1 an 20 */
var userNumber;
var yourNumber;
userNumber = window.prompt('please enter a number in the range 1 to 20','');
while ((userNumber < 1) || (userNumber > 20)) {
userNumber = window.prompt('please re-enter - number should be in range 1 to 20', '')
}

document.write('The user\'s chosen number was ' + userNumber);
document.close()
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
-------------------------------------------------
Question 2

<HTML>
<HEAD>
<TITLE> Activity_8.2.5 </TITLE>
<SCRIPT >
/* Program to read in a known number of data items and store them in an array */
var rainArray = new Array (5);
document.write('Array program to read in a known number of data items');
for (var month = 0; month < rainArray.length; month++) {
rainArray[month] = window.prompt('Enter rainfall value','')
};
document.write('' + '');
document.write('Confirmation of data input' + '' + '');

for (var month = 0; month < rainArray.length; month++) {
document.write(rainArray[month] + ' ')
}
</SCRIPT>
</HEAD>
<BODY> </BODY>
</HTML>

Collapse -

by john.cb1 In reply to

Poster rated this answer.

Collapse -

by john.cb1 In reply to Javascript programs

Point value changed by question poster.

Collapse -

by john.cb1 In reply to Javascript programs

This question was closed by the author

Back to Software Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums