Pls i need a correction to this code. I will love a solution that uses if else statement and for loop. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Pls i need a correction to this code. I will love a solution that uses if else statement and for loop.

I want to write a program that will ask user to enter a number, and output the square of the number. This is my code function askNumber (){ var user=prompt ("Please Enter a Num ber") if (user ="") return (null) }else if (user=Number) { return Number*Number } } askNumber()

13th May 2019, 10:30 PM
Bolaji Olayinka
Bolaji Olayinka - avatar
2 Answers
+ 4
Hi! Before I answer your question, I advice you to not paste your code inside of the post, instead, write a code, and share the link here. It makes it easier to debug and edit! Now, to the answer. When you're writing code, don't use things which don't help for your desired outcome. A loop won't help with anything here :) Write smart code, not pointless. Below, I linked the most efficient solution to your problem. https://code.sololearn.com/Waz6RrorMEb4/?ref=app
13th May 2019, 10:37 PM
inxanedev!
inxanedev! - avatar
+ 1
Thanks, point taken
13th May 2019, 10:39 PM
Bolaji Olayinka
Bolaji Olayinka - avatar