Today I continued working on arrays. I started by reviewing some of yesterday's material, regarding 2 dimensional arrays. We have a project, making a quiz using an array, that I'm working on.
1. The quiz must ask a series of questions and evaluate each answer.
2. The program should keep track of the number of questions answered correctly.
3. After all the questions are answered, the program should display the number of questions that were correctly answered and the number that the player got wrong.
Regarding the array.
1. We should use a two dimensional array to hold the questions and the answers.
2. Each element of the array represents one question and is itself an array composed of two elements, the question and the answer.
3. Create a two dimensional array with at least three questions in it.
We must use a loop to:
1. Cycle through each question, ask it, then compare the response from the player to the answer in the array.
2. Use the prompt method to ask the question.
3. Then, use a conditional statement to see if the player's answer matches the real answer.
When the loop is done, we should know how many answers were correctly answered, and we should print that out to the screen. Here is the instructor's answer for the quiz:
var questions = [
["How many letters in Madrid?", 6],
["How many letters is Peter?", 5],
["How many letters in beach?", 5],
];
var correctAnswers = 0;
var question;
var answer;
var response;
var html;
function print(message) {
document.write(message);
}
for (var i = 0; i < questions.length; i += 1) {
question = questions[i][0];
answer = questions[i][1];
response = parseInt(prompt(question));
if (response === answer) {
correctAnswers += 1;
}
}
html = "You got " + correctAnswers + " question(s) right.";
print(html);
Next, we have to make the program keep track of the correctly answered and wrongly answered questions, however, before I move on to that, I'm re-doing the quiz problem above, because the concepts that are involved, and the complexity (relative to prior exercises) is really interesting to me, so I want to explore it in depth, by coding it again several times, before I move on. I actually printed out the code above, and I'm taking it to bed with me to read over and over, to fully grasp every section of it.
1. The quiz must ask a series of questions and evaluate each answer.
2. The program should keep track of the number of questions answered correctly.
3. After all the questions are answered, the program should display the number of questions that were correctly answered and the number that the player got wrong.
Regarding the array.
1. We should use a two dimensional array to hold the questions and the answers.
2. Each element of the array represents one question and is itself an array composed of two elements, the question and the answer.
3. Create a two dimensional array with at least three questions in it.
We must use a loop to:
1. Cycle through each question, ask it, then compare the response from the player to the answer in the array.
2. Use the prompt method to ask the question.
3. Then, use a conditional statement to see if the player's answer matches the real answer.
When the loop is done, we should know how many answers were correctly answered, and we should print that out to the screen. Here is the instructor's answer for the quiz:
var questions = [
["How many letters in Madrid?", 6],
["How many letters is Peter?", 5],
["How many letters in beach?", 5],
];
var correctAnswers = 0;
var question;
var answer;
var response;
var html;
function print(message) {
document.write(message);
}
for (var i = 0; i < questions.length; i += 1) {
question = questions[i][0];
answer = questions[i][1];
response = parseInt(prompt(question));
if (response === answer) {
correctAnswers += 1;
}
}
html = "You got " + correctAnswers + " question(s) right.";
print(html);
Next, we have to make the program keep track of the correctly answered and wrongly answered questions, however, before I move on to that, I'm re-doing the quiz problem above, because the concepts that are involved, and the complexity (relative to prior exercises) is really interesting to me, so I want to explore it in depth, by coding it again several times, before I move on. I actually printed out the code above, and I'm taking it to bed with me to read over and over, to fully grasp every section of it.
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
In Progress: "Eloquent JavaScript," by Marijn Haverbeke (On pg 27)
In Progress: "Head First Javascript," by Eric Freeman and Elisabeth Robson (On pg 56)
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
Total Hours Coding: 379.5
No comments:
Post a Comment