Skip to content
Sign upLog in
← Back to Community

Repl.it Precourse assignment help!

Profile icon
Iyehvah

I am confused. It says to write my own loop and a variable is named for me which is "count" and it tells me to add 1 to loop till it gets to 10. I think my loop is correct since i didnt stray too far from the first loop in the repl.it assignment.... please help!

// ------- Please begin your work below this line: -------
function exerciseOne(){
// In this exercise, write a simple 'for loop' that starts the variable 'i' at 0 and
// increases i until it reaches 6.
// Fill in the blanks in the parentheses, and then console.log(i) inside of the fo loop
for( let i = 0; i < 6; i++){
console.log("This is i:", i)
}

// Please write your answer in the line above.
}

function exerciseTwo(){
let count = 0;
// In this exercise write your own for loop (you can look at the syntax above).
// It should loop 10 times.
// You are given a variable called: count .
// For each loop reassign count to the current value of count + 1 .
for( let count = 0; count < 10; count++){
console.log(count)
}
//Please write your answer in the line above.
return count;
}

Answered by vedprad1 [earned 5 cycles]
View Answer
Voters
Profile icon
mandamas1983
Profile icon
prettyhossain06
Profile icon
Iyehvah
Comments
hotnewtop
Profile icon
vedprad1

For Exercise One, it is asking you to simply console.log(i); inside the loop. You are adding the string. That is the problem.

For Exercise Two, count is already defined, so why are you redefining it in the for loop. Use i instead. Also, you are not supposed to return or console.log anything. Like this:

function exerciseTwo() { let count = 0; for (var i = 0; i < 10; i++) { count++; } }

If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!

Profile icon
Iyehvah

@vedprad1
Thanks a lot for the help. I am still a bit confused as to why i had to bring a random variable into the loop.. but thats okay i will review the video again.

Profile icon
HankFried

In the event that you are searching for one of the real CompTIA SY0-601 Dumps Questions PDF sources, then go for DumpsTriner CompTIA SY0-601 pdf dumps design is viable with the gadgets one might have. Like PC, PC and so on this SY0-601 braindumps can be useful to deal with the assignment when you are free. One can utilize CompTIA SY0-601 Exam Questions and Answers PDF now and again to ask anybody. The SY0-601 genuine inquiries and answers pdf arrangement can be useful when you are not free so we might put it all on the line and remember these SY0-601 practice questions are ready by the subject specialists and one can undoubtedly depend on the CompTIA SY0-601 inquiries dumps to make progress in SY0-601 CompTIA Security+ test no time! With the assistance of CompTIA SY0-601 test dumps, one may certainly make progress in CompTIA Security+ test.

Profile icon
mwilki7
function exerciseTwo() { let count = 0; // In this exercise write your own for loop (you can look at the syntax above). // It should loop 10 times. // You are given a variable called: count . // For each loop reassign count to the current value of count + 1 . for( let count = 0; count < 10; count++) { console.log(count) } //Please write your answer in the line above. return count; }

JavaScript allows you to use multiple variables with the same name (not sure about the same scope, someone else will have to confirm that).

You have one 'count' in the first line
let count = 0
and another in the for loop
for (let count = 0...)
The for loop changes the new count instead of the old one.
We need to tell JavaScript not to make a new variable so change:

for (let count = 0...)

to

for (count = 0...)

Not adding the '...' dots of course.

Profile icon
heyitsmarcus

Hey

@iyehvah
, can you please post your code into a new repl that way we can see it? Thanks!

Profile icon
Iyehvah