Today's class deals with "for" loops. The general syntax for this kind of loop is:
for (var i = 1; i < 11; i = i + 1){
console.log(i);
}
The console.log is not a part of the syntax for the loop, we are just using it in order to see the output printed on the log.
for (var i = 4; i < 24; i = i + 1) {
console.log(i);
}
The code above returns every number between 4 and 23, including 4 and 23. The i = i + 1 code can also be written as i++, which will start at the beginning and increment, while i-- will start at the end and decrement. Continuing with this, i += x will increment by the value of x, while i -= x will decrement by the value of x. A JavaScript loop that cannot properly end is called an infinite loop, and it will crash a browser. "For" loops will only run when the condition is true.
These were the instructions:
Once more, for practice: write a
for
loop that gets the computer to count down from 100 until 0 by 5. This time, make sure not to print 0.
And this was my code, which was correct (the i >= 3 can have an x value of 2, 3, 4, or 5).
console.log(i);
}
Next, we started going over arrays. This was my first array:
var junk = ["Data One", "Data Two", 8, 88];
console.log(junk)
The console.log is not a part of the array, it's just what is used to print the output to the log. This will output the 4th element in an array (array numbering starts at 0, so 3 will output the 4th item):
console.log(junkData[3])
This code will print out every element of an array:
var cities = ["Melbourne", "Amman", "Helsinki", "NYC", "Toronto", "Mecca", "Buenos Aires"];
for (var i = 0; i < cities.length; i++) {
console.log("I would like to visit " + cities[i]);
}
This:
var names = ["George", "Edward", "Ralph", "Denise", "Veronica"];
for (var i = 0; i < names.length; i++) {
console.log("I know someone called" + " " + names[i]);
}
Will output "I know someone called George" as well as the same output with the other names. That finished the first section of the "For" loops class.
SUMMARY OF CODING SKILLS
Total Treehouse Points: 4,236
Treehouse Points by Subject Matter: HTML 663, CSS 1,599, Design 1,193, Development Tools 747, and Miscellaneous
Treehouse Ranking (%): "You have more total points than 88% of all students."
Treehouse Badge(s) Earned Today:
Treehouse Courses Completed:
How to Make a Website
HTML
CSS Foundations
CSS Layout Techniques
Aesthetic Foundations
Design Foundations
Adobe Photoshop Foundations
Adobe Illustrator Foundations (66% complete, but switched focus to web dev, as opposed to web design)
Git Basics
Codecademy (& other) Courses Completed:
HTML and CSS (Codecademy)
Design Foundations
Adobe Photoshop Foundations
Adobe Illustrator Foundations (66% complete, but switched focus to web dev, as opposed to web design)
Git Basics
Codecademy (& other) Courses Completed:
HTML and CSS (Codecademy)
Books Read or in Progress:
Completed: "Head First HTML and CSS," by E. Robson & E. Freeman (37 pg preface and 710 pgs of actual content (as in, I'm not including the book's index))
My Progress on The Odin Project:
1. Introduction to Web Development 100% Complete
2. Web Development 101 29% Complete
3. Ruby Programming 0% Complete
4. Ruby on Rails 0% Complete
5. HTML5 and CSS3 0% Complete
6. Javascript and JQuery 0% Complete
7. Getting Hired as a Web Developer 0% Complete
Hours Spent Coding Today: 2
Total Hours Coding: 316