Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (lynfran):

JavaScript

OpenStudy (lynfran):

Write JavaScript code that allows a user to enter 2 numeric values when the web page with the JavaScript loads, and output the larger of the 2 values

OpenStudy (lynfran):

@uri

jaynator495 (jaynator495):

This is simple to do :P

jaynator495 (jaynator495):

Alright, Do you know how to compare values in JS?

jaynator495 (jaynator495):

@LynFran

jaynator495 (jaynator495):

Wait your not even online... >-< In the future if you need coding help i suggest tagging me :P Tag me when your back online :)

OpenStudy (lynfran):

@Jaynator495

jaynator495 (jaynator495):

Oh hi ok

jaynator495 (jaynator495):

So, first up, do you know how to compare values in JS?

jaynator495 (jaynator495):

@LynFran

jaynator495 (jaynator495):

Ugh stop going offline when im trying to help you... Or is it OS just bugging out... i cant tell anymore... xD

OpenStudy (lynfran):

@Jaynator495

jaynator495 (jaynator495):

Im here :P

OpenStudy (lynfran):

i think it OS bugging out

jaynator495 (jaynator495):

Ah, Ok Well answer my question xD

OpenStudy (lynfran):

no i dont know how to

jaynator495 (jaynator495):

Alright, Well in this instance you would want 2 variables, these variables would be defined from either A: A input on a page, or B: A prompt box... On page load you can initiate 2 prompt boxes tied to variables asking for a user entry of a number, Then you would want these numbers to be compared in a if statement... if (a > b) { document.write(a); } else if (a < b) { document.write(b); }

jaynator495 (jaynator495):

Now for the variables being defined, var a = prompt('Please Enter a Number','0'); var b = prompt('Please Enter a Number','0'); if (a > b) { document.write("The Largest of the Two Numbers Is " + a); } else if (a < b) { document.write("The Largest of the Two Numbers Is " + b); } And there you go... thats all there is to it.

jaynator495 (jaynator495):

@LynFran

OpenStudy (lynfran):

im here all the time but i keep getting thrown off @Jaynator495

OpenStudy (lynfran):

ok do u know of any good site where i can learn javascript

OpenStudy (woodrow73):

Here's some free courses; https://www.udemy.com/courses/search/?ref=home&src=ukw&q=javascript&lang=en&price=price-free The reviews are pretty good indicators of the good/bad/ugly too.

OpenStudy (lynfran):

ok thanks

OpenStudy (lynfran):

ok so this would be all i have to write?? var a = prompt('Please Enter a Number','0'); var b = prompt('Please Enter a Number','0'); if (a > b) { document.write("The Largest of the Two Numbers Is " + a); } else if (a < b) { document.write("The Largest of the Two Numbers Is " + b); }

OpenStudy (lynfran):

@Jaynator495

jaynator495 (jaynator495):

Erm... No.. In javascript if it was in html it would need to be ``` <html> <head> <script> var a = prompt('Please Enter a Number','0'); var b = prompt('Please Enter a Number','0'); if (a > b) { document.write("The Largest of the Two Numbers Is " + a); } else if (a < b) { document.write("The Largest of the Two Numbers Is " + b); } </script> </head> <body> </body> </html> ```

jaynator495 (jaynator495):

YEa ._.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!