Midterm Review

CS133JS Beginning Programming: JavaScript

Topics by Week 
1. Intro to JavaScript programming6. Arrays
2. Functions, Operators and Expressions7. Objects
3. Conditional Statements: if and switch8. Methods
4. Repetition: while, do while, and for9. DOM
5. Midterm Check-Point10. Final

 

Table of Contents

Announcements and Discussion

Introduction

This week is your opportunity to review all that we've covered in the first four weeks of classboth as preparation for the midterm quiz as well as a way to firm up what you've learned about JavaScript so far.

Focus on understanding conceptsnot on memorizing answers. The only thing to memorize is some terminology. The rest of what you need to know is how JavaScript works and how to write code.

 

About the Quiz

 

What to Review

Lecture notes

Review all the lecture notes and example code for the class, starting at week 1. If there is anything you are unsure about, copy the example code into a browser console and experiment with it. Modifying code to see what happens a great way to learn!

A good way to get a quick overview of what we covered is to look at the review section on each of the lecture notes.

Example code

Download the instructor's examples and play with the code. Put breakpoints in it, and before you run it, try to predict what will be in the variables, then run it and when it stops at the breakpoints, see if you were right. Modify the code and experiment.

Lab assignments

Review the code you wrote for the lab assignments. Make sure you understand how everything works. If there are things you don't understand, look for answers in the required and supplemental readings, lecture notes and post questions in the Moodle Q and A forum.

Practice Quiz

There is a practice quiz available on Moodle that has the same style questions and covers the same concepts as the real quiz but using different questions. As you take the practice quiz, focus on understanding concepts, not on memorizing answers.

Programming Practice

In order to do well on the midterm quiz and on the homework for the second half of the term, you need to understand the underlying concepts behind the questions and programming problems--not just "the answers". In order to better understand those concepts here are some more practice problems:

Selection Problems

For each of these problems write a block of code (not a function) using a selection statement, or statements. Before writing the code, make a table showing the inputs and outputs.

  1. A student is trying to decide which used car to buy. They want a car that meets this criteria:

    • Gets 35 MPG or better.

    • Costs less than $5,000.

    • Has a reliability rating of over 4 on a 1 to 5 scale.

    The selection code should use the criteria above to give output of either "Buy the car", or "Don't buy the car."

  1. You are writing code for the dice game "Pig". In this game, On a player's turn they roll a die. If the die shows any number other than 1, the number they rolled is added to their score and they can roll again, otherwise their score is set to zero and their turn ends.

    • The input to this block of code is the number rolled on the die as well as their current score.

    • The output of this block of code is their new score and whether or not they can roll again.

  2. Write code that will determine whether each of a small set of foods are primarily a: starch, protein, fruit, or vegetable. Some possible foods are: potato, beef, beet, pinto bean, apple, asparagus, onion, tomato, tofu.

Functions

Put each of the blocks of code above into a function.

Repetition

Use an appropriate loop in a new solution involving each of the problems above:

  1. Add a loop outside the function that asks the user to enter information about another car.

  2. a) Add a loop that will iterate again only if the player is allowed to roll again in the current turn.
    b) Modify the loop so that it counts the number of rolls the player has made in their turn.

  3. Add a loop that lets the user enter another food.

Bonus: Add a loop for input validation to any of these problems.

More Programming Practice

There are links to additional programming practice problems on Moodle:


Creative Commons License Beginning JavaScript Lecture Notes by Brian Bird, written , revised , are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.