Today I continued with the Head First Javascript book, starting on pg 29, where I left off yesterday. I started off the day working on a "99 Bottle of Beer on the Wall" game.
This is the original version:
var word = "bottles";
var count = 99;
while (count > 0) {
console.log(count + " " + word + " of beer on the wall,");
console.log(count + " " + word + " of beer,");
console.log("Take one down, pass it around,");
count = count - 1;
if (count > 0) {
console.log(count + " " + word + " of beer on the wall.");
}
else {
console.log("No more " + word + " of beer on the wall.");
}
}
This is my version, correcting the grammar for when there is only one bottle of beer left on the wall:
var word = "bottles";
var word1 = "bottle";
var count = 99;
while (count > 0 && count > 1) {
console.log(count + " " + word + " of beer on the wall,");
console.log(count + " " + word + " of beer,");
console.log("Take one down, pass it around,");
count = count - 1;
if (count > 1) {
console.log(count + " " + word + " of beer on the wall.");
}
else if (count === 1) {
console.log(count + " " + word1 + " of beer on the wall.");
console.log(count + " " + word1 + " of beer on the wall,");
console.log(count + " " + word1 + " of beer,");
console.log("Take one down, pass it around,");
console.log("No more " + word + " of beer on the wall.");
}
else {
console.log("No more " + word + " of beer on the wall.");
}
}
That was a fun little exercise and a great way to start my day! My next assignment is to build a Battleship-like game using javascript. I set up the index.html file, inserted the link to the external javascript file, and created the external javascript file (battleship.js). The link is like so:
<script src="battleship.js"><script>
I inserted that script right above the closing body tag, where the current standard practice recommends links to external javascript code be inserted. One of the reasons this was recommended as an ideal insertion point is that it allows the webpage to load for the user before any javascript code is processed, so the user can have something to look at in case the code takes some time to process. Sounds reasonable.
When creating a variable, we don't have to necessarily give it a value, and if we don't, then javascript will default the variable to a value of undefined.
This is the original version:
var word = "bottles";
var count = 99;
while (count > 0) {
console.log(count + " " + word + " of beer on the wall,");
console.log(count + " " + word + " of beer,");
console.log("Take one down, pass it around,");
count = count - 1;
if (count > 0) {
console.log(count + " " + word + " of beer on the wall.");
}
else {
console.log("No more " + word + " of beer on the wall.");
}
}
This is my version, correcting the grammar for when there is only one bottle of beer left on the wall:
var word = "bottles";
var word1 = "bottle";
var count = 99;
while (count > 0 && count > 1) {
console.log(count + " " + word + " of beer on the wall,");
console.log(count + " " + word + " of beer,");
console.log("Take one down, pass it around,");
count = count - 1;
if (count > 1) {
console.log(count + " " + word + " of beer on the wall.");
}
else if (count === 1) {
console.log(count + " " + word1 + " of beer on the wall.");
console.log(count + " " + word1 + " of beer on the wall,");
console.log(count + " " + word1 + " of beer,");
console.log("Take one down, pass it around,");
console.log("No more " + word + " of beer on the wall.");
}
else {
console.log("No more " + word + " of beer on the wall.");
}
}
That was a fun little exercise and a great way to start my day! My next assignment is to build a Battleship-like game using javascript. I set up the index.html file, inserted the link to the external javascript file, and created the external javascript file (battleship.js). The link is like so:
<script src="battleship.js"><script>
I inserted that script right above the closing body tag, where the current standard practice recommends links to external javascript code be inserted. One of the reasons this was recommended as an ideal insertion point is that it allows the webpage to load for the user before any javascript code is processed, so the user can have something to look at in case the code takes some time to process. Sounds reasonable.
When creating a variable, we don't have to necessarily give it a value, and if we don't, then javascript will default the variable to a value of undefined.
SUMMARY OF CODING SKILLS
Total Treehouse Points: 5,151
Treehouse Points by Subject Matter (Miscellaneous not included):
HTML: 663
CSS: 1,599
Design: 1,193
Development Tools: 747
Javascript: 916
Treehouse Ranking (%): "You have more total points than 91% 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, switched focus from web design to web dev)
Git Basics
Introduction to Programming
Javascript Basics
Codecademy (& other) Courses Completed:
HTML and CSS (Codecademy)
Design Foundations
Adobe Photoshop Foundations
Adobe Illustrator Foundations (66% complete, switched focus from web design to web dev)
Git Basics
Introduction to Programming
Javascript 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
In Progress: "Eloquent JavaScript," by Marijn Haverbeke (On pg 27)
In Progress: "Head First Javascript," by Eric Freeman and Elisabeth Robson (On pg 51)
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: 4.5
Total Hours Coding: 365.5