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?

After the for loop completes, what is the value of currentCupsOfRice?

Why do you have currentCupsOfRice < 6; in your for loop condition?

its from a exercise I was doing
Screenshot 2022-09-08 133434
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
Screenshot 2022-09-08 133434

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 input = fs.readFileSync(process.stdin.fd, "utf-8").trim().split("\n");

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’s curriculum pages.
If you want a reference to the section about loops, let me know.

var fs = require(“fs”);
var input = fs.readFileSync(process.stdin.fd, “utf-8”).trim().split(“\n”);

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

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

1 Like

It appears you were given this line to be able to use requiredCupsOfRice in the code to determine when to stop printing “The bowl contains X cups of rice.” and print “We have enough rice!”.

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