Check out a free preview of the full Introduction to JavaScript course

The "Looping Exercise" Lesson is part of the full, Introduction to JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to to write a loop that prints a concatenated string to the console.

Preview
Close

Transcript from the "Looping Exercise" Lesson

[00:00:00]
>> Brian Holt: So I have a little exercise for you. Let's go back to our browser here, and we're going to go to frontendmasters.github/io/bootcamp.
>> Brian Holt: Come back to the Boot Camp site. Come down to Programming Fundamentals.
>> Brian Holt: And we're gonna do a little CodePen here.
>> Brian Holt: So I'm gonna click here, Edit on CodePen to open this in CodePen.

[00:00:41]
>> Brian Holt: So what I want you to do, I want you to combine two of the things that we've talked about so far, which is string concatenation.
>> Brian Holt: And I want you to do a loop and you can do either a while loop or a for loop.
>> Brian Holt: So basically the idea is you're gonna have some character here, so you can have const character = f or something that.

[00:01:12]
>> Brian Holt: This is probably the smallest. Let's make that a lot bigger.
>> Brian Holt: And const timesToRepeat. Go with something like 5. And then I want you to write a for loop here or a while loop here that will take this character and add itself to itself that many times.

[00:01:35]
So that I end up with a string like f, f, f, f, f five times. So that whenever I say, let myString or something like that,
>> Brian Holt: This is called an empty string right here which you probably will need. An empty string is a string with no characters in it, right?

[00:01:56]
So it's not undefined, it is a string, the string just has nothing in it.
>> Brian Holt: You're gonna put your code here.
>> Brian Holt: Some sort of loop.
>> Brian Holt: I don't care. And then, at the end, I want you to be able to console.log(myString) here. And that will log out f, f, f, f.

[00:02:30]
>> Brian Holt: Or let's do t, or something like that.
>> Brian Holt: Makes sense, yeah.
>> Speaker 2: I was just wondering. Earlier, you pointed out that when it's a constant you use a different way of labeling, like all capitals? And here you're not doing that, so is it not used that much in the real world?

[00:03:01]
>> Brian Holt: Yeah, it would be more things that are like fixed in the physical world, like months in a year. That's never gonna change, right? It's more, or like the, I don't know, days in a month or something like that. Not necessarily something like a variable here, right. So I wouldn't make this in screaming case, right.

[00:03:22]
That's why it's called screaming case. Does that make sense?
>> Speaker 2: Because it could be a, or b, or c?
>> Brian Holt: Yeah, and it could change at a later date, right? Months and years, never gonna change.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now