Can anyone tell me what is wrong with this code?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone tell me what is wrong with this code??

I am trying to create a code that first prompts from the user the number of values he wants to add . then prompts from the user the number of the values. Then displays the sum through an alert box var i=prompt("enter the number of values whose sum is to be calculated"); var g=0; var f=0; while (g<=i) { f+=prompt("enter the values"); g++; document.write(f); } /*anyone plz tell me what is wrong with this code*/

1st Aug 2020, 5:50 AM
anmol saxena
anmol saxena - avatar
8 Answers
+ 3
anmol saxena You wrote JavaScript code in Java language then how your code will work. Don't put your email as code name. https://code.sololearn.com/ckzqV2392Pr7/?ref=app You must know Java and JavaScript both are different languages.
1st Aug 2020, 5:52 AM
A͢J
A͢J - avatar
+ 3
Can you please tag a relevant language? your tag contains '??' which is meaningless and irrelevant. Follow this tips for posting a question 👍 https://www.sololearn.com/Discuss/333866/?ref=app
1st Aug 2020, 5:54 AM
Ipang
+ 1
Thank u ipang
1st Aug 2020, 1:07 PM
anmol saxena
anmol saxena - avatar
0
I M newbie
1st Aug 2020, 7:09 AM
anmol saxena
anmol saxena - avatar
0
anmol saxena Go to Code Playground, create new code, this time choose Web from language choice, then paste your code into the JS tab 👍
1st Aug 2020, 10:07 AM
Ipang
0
But it is still not working
1st Aug 2020, 1:07 PM
anmol saxena
anmol saxena - avatar
0
anmol saxena Can you share that new code link here so I can take a look? Follow the below guide to sharing links 👇 https://www.sololearn.com/post/75089/?ref=app
1st Aug 2020, 2:54 PM
Ipang
0
java.util.*; class Main { public static void main(String[] args) { System.out.println("enter the number of values whose sum is to be calculated"); Scanner keyboard = new Scanner(System.in); var i = keyboard.nextInt(); var g=0; var f=0; while (g<i) { System.out.println("enter the values"); f+=keyboard.nextInt(); g++; } System.out.println("The sum is : " + f); } }
2nd Aug 2020, 10:43 PM
Moges Ashagrie
Moges Ashagrie - avatar