JavaScript
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
@uri
This is simple to do :P
Alright, Do you know how to compare values in JS?
@LynFran
Wait your not even online... >-< In the future if you need coding help i suggest tagging me :P Tag me when your back online :)
@Jaynator495
Oh hi ok
So, first up, do you know how to compare values in JS?
@LynFran
Ugh stop going offline when im trying to help you... Or is it OS just bugging out... i cant tell anymore... xD
@Jaynator495
Im here :P
i think it OS bugging out
Ah, Ok Well answer my question xD
no i dont know how to
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); }
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.
@LynFran
im here all the time but i keep getting thrown off @Jaynator495
ok do u know of any good site where i can learn javascript
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.
ok thanks
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); }
@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> ```
YEa ._.
Join our real-time social learning platform and learn together with your friends!