Overview

For this week, the weekly reading will focus on programming a little more JavaScript much like the lab this week. For this, you will need a plain text editor on the computer you wish to use to complete the assignment:

File Download

You will need to download and extract the a ZIP file to work on this weekly assignment. You can download the ZIP here.

If you do not remember how to extract a file, you can review the lab assignment here. If you open the HTML file and the text is not centered and contained within a black box, then you did not extract the zip file.

Part #1

For the first part of this assignment, open 1-js.js. You must complete the compute(n) function so that the function will return a value based on the following rules:

To test your code, open 1-html.html in a web browser. The web page will display the result of your code. When your code completes the task, you should see a message telling you that your code worked!

Part #2

For the second part of this assignment, open 2-js.js. You must complete the areTheyAllTheSame(a, b, c) function so that the function will return a value based on the following rules:

Hint: Up to now, you have only seen if-blocks contain a single boolean expression. In order to complete this, you will need to put an if-block inside of another if-block. Be careful with your curly braces!

To test your code, open 2-html.html in a web browser. The web page will display the result of your code. When your code completes the task, you should see a message telling you that your code worked!

Submission

Click here to submit your assignment!

Helpful Resources

Cheat Sheet

You can view the entire slide set from Wednesday's lecture here, but here is a quick overview of the cheat sheet given at the end of lecture:

Examples of Statements
Statements always end in a semicolon
___________________;
x = x + 1;
var orange = 4;

Examples of Variables
var n;
var a = 0;
a = a + 1;

Examples of a Conditional
if (x < 3)
{
...statements go inside the braces...
}

Examples of Booleans
n < 3
n > 3
n == 3
n != 3

Examples of a Function
function name(p1, p2)
{
...statements go inside the braces...
return ___________________;
}

Something didn't work?

Your JavaScript should work in any browser, but some browsers are designed to be focused on developing a web page as much as they are on viewing a web page. Internet Explorer, the default browser on most systems, does not come with any included debugging tools.

The first thing to try is to try a second browser. If your code does not work with both browsers -- something is wrong! Check to make sure everything is spelled correct, the capitalization of your variables are the same in every place, and that you have declared all of your variables.

CS 105 (Spring 2014): Introduction to Computing