Created
October 20, 2014 21:17
-
-
Save chrisdhanaraj/eebcc92575d4d11de8d5 to your computer and use it in GitHub Desktop.
Definitions of Javascript: JS JAMZ #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Defintions | |
// Numbers | |
// 4, 5, 28, 1003, 42, 3.423 | |
var meaningoflife = 42; | |
console.log(meaningoflife); // 42 - no quotations, no brackets, no squigglies, no nuthin' | |
// math operations | |
var three = 1 + 2; // addition | |
var five = 10 - 5; // subtraction | |
var ten = 5 * 2; // multiplication | |
var two = 4 / 2; // division | |
// String | |
// 'meaning of life' | |
var meaning = 'meaning of life'; | |
// Basic operations | |
var concat = 'meaning ' + 'of ' + 'life'; // 'meaning of life' | |
var length = meaning.length; // syntax: parent.length; | |
var position = meaning.indexOf('m'); // syntax: parent.indexOf(search); google MDN indexOf | |
// Two different ways of slicing string | |
// slice, substr | |
// syntax tax for slice | |
// parent.slice(beginning, end); | |
console.log(meaning.slice(0, 2)); // 'mea' | |
// syntax for substr | |
// parent.substr(beginning, length); | |
console.log(meaning.subtstr(4, 10)); // 'ing of life' | |
// Objects | |
// syntax: var obj = { 'key' : value } | |
function checkAge(object) { | |
return object['age']; | |
} | |
var laura = { | |
'name' : 'Laura', | |
'age' : 26, | |
'personality' : ['Rule follower', 'Dominatrix'], | |
'checkAge' : checkAge | |
}; | |
var lauraAge = laura.checkAge(laura); | |
console.log(lauraAge); // 26 | |
// Functions | |
function movieName(movie){ | |
return movie['name']; | |
} | |
var batman = { | |
'name' : 'Batman Begins', | |
'genre' : 'Action/Adventure' | |
} | |
var superman = { | |
'name' : 'Man of Steel', | |
'genre' : 'Action/Adventure' | |
} | |
var batTitle = movieName(batman); //Batman begins | |
var supTitle = movieName(superman); | |
// var batTitle = batman['name';] | |
function setVideoWidth() { | |
var videos; | |
videos = document.getElementsByTagName('video'); | |
// array of every video elements | |
for (var i = 0; i < videos.length; i++) { | |
videos[i].style.width = '100px'; | |
} | |
return videos; // for logging purposes | |
} | |
var videoList = setVideoWdith(); | |
// array of all videos on page | |
// Next time | |
// Recap: functions, arrays, objects | |
// Going over Loops | |
// You're going to get a similar quiz | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment