Need help with Javascript!!! Please!!?
-
Someone, please help me! I have a Javascript homework assignment and I am very lost / stuck... My instructions are to "Write a page which displays a button, when the button is clicked, a javascript function will be called to process the button. It will first ask the user to enter the number of values to be processed by using window object's prompt method. The user will enter a number (ie. 3). Your program will use window object's alert method to alert the user about user's input." ** ^^ I have done this part, it's the next part that I really really need help with, I have been trying for the past week and am running out of time. In this part "Your script contains another two javascript functions which can compute square and cube functions of a value given as a parameter. Your program will loop 3 times, the final result will be a table that contains the results which output iteration number, the value entered, the square of the number and the cube of the number. *Note your program contains at least three javascript functions. One to process button click event, one for square function and the other to compute the cube function." Here is my code: <head> <script type="text/javascript"> function prompter() { var reply = prompt("Please Enter Number of Values for Process:", "") alert ( "Preparing to Enter " + reply + " Values for Process.") } </script> </head> <body> <input type="button" onclick="prompter()" value="Process Data Now!"> </body> ~ I don't understand how to loop; if you try my code the first part works no problem; how do I make the prompt box to prompt again after the value is entered? It needs to square the number then cube it... Please if you're good with javascript and are kind please help I have no idea where to get help anymore... Thank you!
-
Answer:
<html> <head> <script type="text/javascript"> function prompter() { var reply = prompt("Please Enter Number of Values for Process:", "") alert( "Preparing to Enter " + reply + " Values for Process.") var num=new Array(reply); result='<table border="1"><tr> <td>Iterator</td> <td>Input value</td> <td>Square</td> <td>Cube</td></tr>'; for(a=0;a<reply;a++){ num[a]=prompt("Enter number "+a, ""); result+='<tr><td>' +a+'</td><td>' +num[a]+'</td><td>' +square(num[a]) +'</td><td>'+cube(num[a]) +'</td></tr>'; } result+='</table>'; document.getElementById( "output").innerHTML=result; } function square(inum){ return inum*inum; } function cube(inum){ return Math.pow(inum,3); } </script> </head> <body> <input type="button" onclick="prompter()" value="Process Data Now!"> <div id="output"></div> </body> </html>
moltonbo... at Yahoo! Answers Visit the source
Related Q & A:
- I need help on what I need to buy or do.Best solution by Yahoo! Answers
- I did something really bad and now i need help please help me.Best solution by Yahoo! Answers
- Anybody psychic or clairvoyant? I really need some help and advice please. Please see question below?Best solution by Yahoo! Answers
- I need help with my camera, please.Best solution by Yahoo! Answers
- Need help debugging a javascript?Best solution by allwebdevhelp.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.