# Need help adding a string to my for loop at the end

this is the Question :

• Using the supplied variables, create a loop of your choice that will add cups of rice to a bowl. Each time a cup of rice is added, print “The bowl contains X cups of rice.”, where X is the number of cups added. Once the number of cups called for has been reached, print “We have enough rice!”.

Im trying to implement the last part “We have enough rice!”. at the end of the code block but I don’t know how to add it heres my code so far :

``````var input = 0;

var requiredCupsOfRice = parseInt(input[0]);
var currentCupsOfRice = 0;

for (let currentCupsOfRice = 0 ; currentCupsOfRice < 6; ++currentCupsOfRice){
console.log(`the Bowl contains \${currentCupsOfRice} cups of rice`);

}
``````

hi there,

Is this program for an fCC exercise? if yes, can you link to the specific page in the curriculum?

Also I am interested to know why you defined this variable but did not use it in the code?

its from a exercise I was doing

this is suppose to be the expected solution according to the exercise.

I was trying to find the correct solution from what I know its a exercise from a online course im taking he variable was already defined . this is the solution they expect they want me to use a for loop

ah okay. Thank you for clarifying.

What was the initial code given to you? (if you can paste it here?)

this is what they gave me

``````var fs = require("fs");

var requiredCupsOfRice = parseInt(input[0]);
var currentCupsOfRice = 0;
``````

okay. Great. I was wondering if you have any experience writing code?
Usually when you are given some lines of code to complete a programming exercise, you are expected to use them.

So what do you think the line below is for?
var requiredCupsOfRice = parseInt(input[0]);

im not sure I posted the question they gave me and this is the code they gave. sometimes theres multiple solutions to a given problem that they will accept but i have no clue what this is cupsrequired is for for I looked up the word parse and mentions a string interger I was confused.

no problem. Please read here first to understand this line of code.

Once you have done that. You can try the problem given to you again.
(this time using this variable in your loop)

Also there is a python class available for free on freecodecamp.org’s curriculum pages.
If you want a reference to the section about loops, let me know.

var fs = require(“fs”);

var requiredCupsOfRice = parseInt(input[0]);
var currentCupsOfRice = 0;

do{
currentCupsOfRice++;
console.log(`The Bowl contains \${currentCupsOfRice} cups of rice`);
if(currentCupsOfRice===requiredCupsOfRice){
console.log(‘We have enough rice!’);}
} while(currentCupsOfRice<requiredCupsOfRice);

1 Like

hallo Grosu! Welcome to the forum!

Were you trying to help the original poster (OP) by posting a solution for him?
If yes, I am sure the OP will appreciate that, but maybe not for a very long time because he will not learn how to code but only how to copy-paste code.

this is JavaScript not python . I already know about w3 schools i just needed help with one part of my code. I think its better to explain the solution if youd like to help sending links isn’t much helpful but thanks.

i don’t understand what you mean.

Sorry about that. I must have thought it was python for a weird reason…

Still if you can look up what the input does it will help you move forward.
But anyway, that is just my opinion.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.