Hi guys im doing a course which includes some JavaScript and I need help with the following question please,
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.
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 5617 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 Children aged 4 to 12
4) Number of Children under age 4
|
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. Using
the javascript debugger, it seems that everything is working at that
end, so I wonder if the problem is mozilla/css related. The live page
is at http://www.smalltime.com/exhibitions/washanddry
Here is the relevant html and javascript...
|
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 Mozillas,
neither Firebird nor Firefox (and not in Netscape 7.something).
What is wrong with it? I'm no javascript expert, I just got it
from the net years ago, I don't even know where from. There is
no source url given in it to look up. I've...
|
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?
Here's my code (CMS and INCHES which is working):
<input name="CM" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('IN.value = ' + this.form.IN_expr.value)">
cms <em>or</em>
<input name="IN" type="text" VALUE="" size="3" maxlength="3"
|
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 could help me out here.
Below is the complete script.
<SCRIPT language="JavaScript1.2">
var cursorpath="http://i68.photobucket.com/albums/i9/worklog_halcyon/Misc/pet1_lohi_dog.png"
if (document.layers)
| |
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!
The 'floating layer' does not float in IE7... it just sits up at the top of the screen - stuck in one place!! Explorer - why do you mock us?!!! ;(
I have tried everything - but I am at a loss.
I am thinking maybe it's some conflicting CSS or some...
|
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 the "Downpayment" and also the "Total
amount paid"
Example: item cost $20.00 , $8.50 shipped selected,
Payment 1 = 12 + 8.50 so $20.50
Payments 2-5 = $2.00
Final Payment = $28.50
|
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>
<SCRIPT language=JavaScript>
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |