function sayHello() {
try {
var saying = "Hello";
aler(saying);
}
catch(err) {
alert(err);
}
}
What that does is that, the code will break at alert, because it's misspelled, and then catch will be triggered, creating an alert with the err message (the alert will read: "Reference Error: Can't find variable: aler").
Try and catch are always paired, but their usefulness is limited, as the code itself can become quite convoluted if you keep wrapping it in try...catch blocks.
O.k., I'm done with chapter 87, now I'm on Chapter 88 Exceptions: Throw. The throw code can send any type of value, including a number or boolean, to the catch parameter. You can also pass a variable.
O.k., I'm done with chapter 88, now I'm on the final chapter, Chapter 89 Handling Events Within JavaScript. We should refrain from inserting JavaScript directly into HTML, so when we use onClick followed by a JavaScript function, this is bad practice. Instead, what we should do is give the HTML element an id, then in the separate JavaScript document with all the JavaScript code, do this:
var b1 = document.getElementById("thesampleid");
b1.onclick = sayHello;
sayHello would be the function that would have previously been written into the HTML like so: onClick="sayHello();"
Note that in the HTML, we use camelCase for onClick, but in the JavaScript, we do not, using onclick instead. This code works as well:
document.getElementById("thesampleid").onclick = sayHello;
The function could be something like:
function sayHello() {
alert("Hi there.");
}
You can do that with all kinds of functions, like the ones we worked on previously to swap images or verify email address entries. I thought this code was neat:
<input type="button" value="Click" id="b">
<script>
document.getElementById("b").onclick = message;
function message() {
alert("You clicked!");
}
</script>
But like we said, we should keep the JavaScript in a separate file.
That's it, I'm done with the book. That was 89 chapters, with 20 coding questions/problems per chapter, for a total of 1,780 coding questions/problems. I feel fantastic. What a great day.
Now, it's back to The Odin Project, let's get it done as soon as possible and take my coding skills to the next level!!!
Woohoo!
SUMMARY OF CODING SKILLS
Total Treehouse Points: 5,385
Treehouse Points by Subject Matter (Miscellaneous not included):
HTML: 663
CSS: 1,599
Design: 1,193
Development Tools: 747
JavaScript: 1,120
Treehouse Ranking (%): "You have more total points than 94% 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 (768 pgs.)
In Progress: "Head First JavaScript," by Eric Freeman and Elisabeth Robson (on pg. 56)
Completed: "A Smarter Way to Learn JavaScript," by Mark Myers (293 pgs., 89 chapters in this book, with 20 coding questions/problems per chapter, for a total of 1,780 JavaScript questions/coding problems answered)
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: 615
No comments:
Post a Comment