Build a tic-tac-toe game!
Available on CS 105 Website by 3:00pm
Due: Tuesday, Feb. 24, 8:00pm
Functions, loops, and other JavaScript!
Available tonight, 5 problems, +2 extra credit problems
Due: Monday, Feb. 23, 9:00am
Labs so far will be graded generously, if you did the lab you'll earn all the points.
Gradebook online soon, will send e-mail when online.
Midterm 1 is Tuesday, March 3rd, 8:00pm-9:30pm
Two weeks from yesterday!
var num = 43; // Number
var s = "Hello"; // String
// Function:
var f = function() { ... };
// Array (of Strings):
var a1 = ["a", "b"];
// Array (of Numbers):
var a2 = [37, -375];
var b = true; // Boolean
Boolean have only two possible values: true or false.
Boolean are the result of comparisons.
var a = 3; var b = (a < 5); console.log(b);
Functions will often return a Boolean value.
/**
* Returns true if the input
* parameter (temp) is at or
* below 32, false otherwise.
*/
var isFreezing = function(temp) {
};
In our previous coding example, we added strings!
var a = "Hello"; var b = "World"; var c = a + b; // "HelloWorld"
Adding two strings together will join them into one string. This is called string concatenation.
Lets average a list one more time...
var a = [ 93, 97, 82 ];
When adding, subtracting, multiplying, or dividing when the result is going into the same variable, you can use a shortcut!
var a = 5;
a += 2; // Add two to a
// Same as: a = a + 2
a *= 5; // Multiply a by five
// Same as: a = a * 5
var b = 3;
b -= 3; // Subtracts three from b
// Same as: b = b - 3
b++; // Adds one to b
// Same as: b = b + 1, b += 1
b /= 5; // Divide b by 5
// Same as: b = b / 5
x++; // Adds one to x x += a; // Adds the value in a to x x--; // Subtracts one from x x -= a; // Subtracts a form x x *= a; // Multiply value in x by a x /= a; // Divide the value in x by a
Suppose we want to calculate our average GPA based off our letter grades.
var grades = ["A", "C", "B+", "A-", "B"];