I just wanted to eat some pasta. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I just wanted to eat some pasta.

So I am the average Italian, and during Sundays all my family gathers to eat some pasta together. I thought to make a code to calculate how many people are eating and how much pasta to cook could have been a good and simple idea. And oh mamma mia if I wasn't mistaken. In the code, I put in <input type ="number"> a value referring on how many grams of pasta a certain person is eating (default 80). When the checkbox is checked, I expected the number to be added to a variable later used to calculate the total grams. Instead it just adds "80" to the variable like it was a string. - The issue is before the comment with many "!!!!!" - You can ignore the second checkbox and form - No we aren't 2 in the family Thanks, this has been driving me insane for 3 hours. https://code.sololearn.com/W6W5ECNhMEXQ/?ref=app

23rd Feb 2019, 4:11 AM
Matteo Consolaro
Matteo Consolaro - avatar
3 Answers
+ 3
And that's bcz 'value' will always return a string and not a number. Just a little correction at line 30, you need to convert the 'value' to Number. grams += Number(numAdd);
23rd Feb 2019, 4:15 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 3
Matteo Consolaro to be rigjt it is class so you create new object of class Number, which is simply number
23rd Feb 2019, 7:33 AM
Maneren
Maneren - avatar
+ 1
Shashi Ranjan Oh.. So it was really like that. Thanks a lot, I didn't know the Number function.
23rd Feb 2019, 4:22 AM
Matteo Consolaro
Matteo Consolaro - avatar