1.2 Hello, World
Data Types, Variables, and Arrays
Objectives
- Describe the concept of a "data type" and how it relates to variables
- Describe use cases of different "data types"
- Declare, assign to, and manipulate data stored in a variable
- Explore and use a programming or markup language's standard library and built-in functions (iterators, datatype/array methods)
- Iterate over and and manipulate values in an array
- Describe how arrays are used to store data
Class Examples
var cocktails = ['gin & tonic', 'white russian', 'mojito', 'sangria', 'grape ape'];
cocktails.pop();
for (var i = 0; i <= cocktails.length; i++) {
console.log('i = ' + i);
console.log(cocktails[i]);
console.log("I could use a... " + cocktails[i]);
cocktails.pop();
}
Class Examples
{
console.log('hello, world');
}
var age = confirm('Are you over 21?');
if (age === true) {
alert('huzzah');
} else {
alert('soon.jpg');
}
var somewhere = window.location.host;
if (somewhere != 'ga-chicago.github.io') {
alert('oh no! this is not the right website.');
} else {
alert('awww yeaah u aint hackd');
}
var userInput = prompt('what is your name?');
if (userInput.length < 1) {
alert('hey, you didn\'t give us your name');
} else {
alert('thanks, ' + userInput + '!!!!!@121211212');
}
if (age >= 21 && hasMoney == true) {
}
if (21 >= 21 && true == true) {
console.log('you can haz booze');
}
if (true || false) {
console.log('boolean party!!@!212');
}
var name = 'james';
if (name === 'james' || name === 'jim') {
console.log('j names rule');
}
var car = 'ford';
switch (car.toLocaleLowerCase()) {
case "mazda": alert('mazdas zoom zoom');
break;
case "nissan": alert('the leaf is green');
break;
default:
alert('your car is not here..?!@');
break;
}
Lab: Introduction to Git & Github