3913 Shares

How do i write a javascript that asks the user to input a number. The number is then passed into a function?

How do i write a javascript that asks the user to input a number. The number is then passed into a function? Topic: How to write a math function
June 25, 2019 / By Camilla
Question: How do I write a javascript that asks the user to input a number. The number is then passed into a function you write that contains a loop. The loop will loop the number you passed into the function and print out the word “ha” that many times. For instance, if I entered 3, the function would print out “ha ha ha”? Any help would be GREATLY appreciated!
Best Answer

Best Answers: How do i write a javascript that asks the user to input a number. The number is then passed into a function?

Alyx Alyx | 1 day ago
Here's a couple of trivial alternatives that differ by how the user gives input...
enter a positive integer:

👍 110 | 👎 1
Did you like the answer? How do i write a javascript that asks the user to input a number. The number is then passed into a function? Share with your friends

We found more questions related to the topic: How to write a math function


Alyx Originally Answered: How to write a C++ program that prompts the user to enter a real number?
#include #include // This is needed for the system("Pause") function #include int main(){ float num = 0; double param, fractpart, intpart; std::cout << "Enter Number\n"; std::cin >> param; /* This function modf does everything you need. The first parameter is the number you entered, the second parameter is where it will store the int value. */ fractpart = modf (param , &intpart); std::cout << "Number: " << param << "\n"; std::cout << "Int part: " << intpart << "\n"; std::cout << "Fraction part: " << fractpart << "\n"; // I use this function so I can see the output on the console before it closes. system("Pause"); return 0; }

Virgil Virgil
Program Inverse_X(Input, OutPut); {$APPTYPE CONSOLE} uses SysUtils; var X, I, L : Integer; S, Reverse_S : String; begin WriteLn('Type a number'); ReadLn(X); S := IntToStr(X); // Transtype integer to String; L := Length(S); Reverse_S := ''; for I := L Downto 1 do begin Reverse_S := Concat(Reverse_S, S[I]); end; Writeln(Reverse_S); ReadLn; end.
👍 40 | 👎 -7

Royale Royale
*sigh* here is the algorithim function name(var number) { var i = 0; loop as long as i is less than number print "HA" add 1 to i end loop } I simply combined my small knowledge of javascript and applied it to my rather much more vast knowledge of C. However its not that difficult
👍 40 | 👎 -15

Morgen Morgen
you should maybe try learning something about javascript? look at this: var name = prompt("What is your name", ""); the name variable now contains whatever the user typed in, the second value in prompt() is just the default value for the loop you probably want a for loop http://www.w3schools.com/js/js_loop_for....
👍 40 | 👎 -23

Keelin Keelin
👍 40 | 👎 -31

Keelin Originally Answered: Program to calculate number of word / occurrences of a user-specified keyword?
I'm not very good at C++ but I think you may need to close the file stream and re-open it between cases.

If you have your own answer to the question how to write a math function, then you can write your own version, using the form below for an extended answer.