Hi guys im doing a course which includes some JavaScript and I need help with the following question please,
The code I have so far is below but I don't think its right please help as I need to complete this part to move onto the next.
Edit M150_TMA05_2008 J_Q1_task01.htm l replacing the existing
JavaScript with the function,
getRoundedRando mNumber(aNumber ). This function should
return whole numbers between 0 and aNumber, using
Math.round() as outlined above.
Write a comment to document what this function does, using an
extended comment (that is, one between /* and */). Also
provide appropriate single-line comments (the ones starting
with //) in the code, describing how it works. Paste a copy of
the getRoundedRando mNumber() function into your Solution
Document.
Also remove the line of code and associated comment you wrote
for part (ii).
2
Read the ONCLICK event handler for the file’s HTML form to
understand how getRoundedRando mNumber() is invoked and
how the returned number is displayed.
JavaScript with the function,
getRoundedRando mNumber(aNumber ). This function should
return whole numbers between 0 and aNumber, using
Math.round() as outlined above.
Write a comment to document what this function does, using an
extended comment (that is, one between /* and */). Also
provide appropriate single-line comments (the ones starting
with //) in the code, describing how it works. Paste a copy of
the getRoundedRando mNumber() function into your Solution
Document.
Also remove the line of code and associated comment you wrote
for part (ii).
2
Read the ONCLICK event handler for the file’s HTML form to
understand how getRoundedRando mNumber() is invoked and
how the returned number is displayed.
Code:
<HTML>
<HEAD>
<TITLE>M150 TMA 5 : Programming : Task 1 - Testing Math.random()</TITLE>
<SCRIPT language = "JavaScript">
//generate a random number greater than or equal to 0.0 and less than 50.0
//rounded to a whole number
//and display it in an alert dialogue
var getRoundedRandomNumber = Math.round(Math.random()*49);
window.alert("Random number returned is: " + getRoundedRandomNumber);
//generate a random number and round down
var getRandomNumber = Math.floor(Math.random()*49)
</SCRIPT>
</HEAD>
<BODY>
<STRONG>A test of the random number functions <BR></STRONG>
<FORM NAME = "randomForm">
<INPUT TYPE = "button" NAME = "randomButton" VALUE ="Display Random Number!"
ONCLICK = "window.alert(getRandomNumber);">
</FORM>
</BODY>
</HTML>
Comment