Hi guys im doing a course which includes some JavaScript and I need help with the following question please,
Edit M150_TMA05_2008J_Q1_task01.html replacing the existing
JavaScript with the function,
getRoundedRandomNumber(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 getRoundedRandomNumber() 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 getRoundedRandomNumber() is invoked and
how the returned number is displayed.
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. - <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>
9 5585 Dormilich 8,658
Recognized Expert Moderator Expert
the first thing you need is a function (see description) where you need to put in the code, so you can call it onclick.
further, your form needs an action attribute. and the script a type attribute. - <form action="name_of_page" … >
-
-
<script type="text/javascript>
Hi, any chance of an example of what function code you would use, I'm pretty useless but trying to learn lol
Dormilich 8,658
Recognized Expert Moderator Expert
the task requires you to write - function getRoundedRandomNumber(aNumber)
-
{
-
// put your code here
-
-
return roundedNumber;
-
}
and then write some code to call this function onclick.
hint: the basic idea is outlined in the task
My attempt was as follows; - Function getroundedrandomnumber(aNumber)
-
{
-
var aNumber = Math.floor(Math.random()*49);
-
-
return aNumber;
-
}
Help please lol
acoder 16,027
Recognized Expert Moderator MVP
JavaScript is case-sensitive, so make sure the case is absolutely correct and also look at the error console.
I'm typing on my iPhone in work and using notepad to right the script lol
acoder 16,027
Recognized Expert Moderator MVP
But you must be testing it in a browser, no?
Ah i see what you mean it says 'aNumber' is undefined
Thanks for the help guys I don't know how but I made it work the error console tip was great will post code when I get home, cheers again
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Michael Hagstrom |
last post by:
Good Day -
I have written a form which collects input for a fare calculation. The form
collects the following:
1) Departure or Destination Group (1,2,or 3)
2) Number of Adults
3) Number of...
|
by: gene |
last post by:
I have some javascript code that displays random images in random
places on the page by making changes to the document's css. This
works in Safari and IE, but I can't get it to work on Mozilla. ...
|
by: Cat |
last post by:
Greetings,
I have an old javascript effect that was running on some of my
sites for quite long, working fine in Netscape (up to 4.75) and
IE. It still works in the newer IEs, but not in the new...
|
by: JS |
last post by:
I've managed to create a simple script to convert between metric and
imperial. It works for CMS to INCHES and vice versa but not for KGS to
STONES/POUNDS. Can anyone shed any light on this?
...
|
by: ArcInversion |
last post by:
Hi, I've been using a javascript script to create a dragon that flies across the page. Anyways, I'd like to make it so when you click the dragon it takes you to a new page. Was wondering if anyone...
| |
by: Head In A Pan |
last post by:
Hello!
My JavaScripting is at novice level - and after completing a tutorial on a 'floating layer' I was proud that I got it working on Firefox, Safari, Camino & even IE5 for mac!!! But not IE7!...
|
by: Yonih |
last post by:
So I am trying to get this Calculator to work. It needs to take in a
vaule, and select a shipping
Everythin works great except the shipping part. I need it to take the
shipping value and add it to...
|
by: Bugsy1937 |
last post by:
Hello Folks,
I wrote the following long ago and it worked for years. It Still works in IE, but can't get it to work in Firefox3.
Here's the script, hope someone can help me:
<html>
<body>...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |