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
var userChoice = prompt("Do you choose rock, paper or scissors?"); | |
var computerChoice = Math.random(); | |
if (computerChoice < 0.34) { | |
computerChoice = "rock"; | |
} else if(computerChoice <= 0.67) { | |
computerChoice = "paper"; | |
} else { | |
computerChoice = "scissors"; | |
} console.log("Computer: " + computerChoice); |
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
function wisePerson(wiseType, whatToSay) { | |
// your code here | |
var wiseQuote = 'A wise ' + wiseType + ' once said: \"' + whatToSay + '\".'; | |
console.log(wiseQuote); | |
return(wiseQuote); | |
}; | |
/* From here down, you are not expected to | |
understand.... for now :) |
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
function computeArea(width, height) { | |
// your code here | |
area = width * height; | |
return(area); | |
}; | |
/* From here down, you are not expected to | |
understand.... for now :) | |
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
function doTrafficLights() { | |
var activeLight = getActiveLight(); | |
// your code will replace this call | |
// to `console.log()` | |
if (activeLight === "red") { | |
turnRed(); | |
} else if (activeLight === "green") { | |
turnGreen(); | |
} else { |
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
function max(numbers) { | |
// your code here | |
for (i = 0; i < numbers.length; i++) { | |
var max = 0; | |
if (numbers[i] > max) { | |
max = numbers[i]; | |
}; | |
}; | |
return(max); | |
}; |
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
-- What is scope? Your explanation should include the idea of global vs. local scope. | |
Scope refers to the effective domain of a given variable. In Javascript EC5, variables either have 'global' or 'local' scope. | |
When variables have 'local scope', they are only accessible within that particular scope. For instance, if, within a given function, you defined a variable like so: | |
var foo = "bar"; | |
That variable would only be accessible within the function it was called. If, outside of said function, one tried: | |
console.log(foo); |
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
function createMyObject() { | |
// your code here | |
var myObject = { | |
foo: 'bar', | |
answerToUniverse: 42, | |
'olly olly': 'oxen free', | |
sayHello: function() { | |
return("hello"); | |
} | |
} |
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
function mostFrequentWord(words) { | |
// your code here | |
// `words` is an array of strings. | |
var wordFreq = {}; | |
for (var i = 0; i < words.length; i++) { | |
if (words[i] in wordFreq) { | |
wordFreq[words[i]]++; | |
} else { | |
wordFreq[words[i]] = 1; |
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
JS Bin Links: | |
Drill 1: | |
https://jsbin.com/goheya/edit?html,css,js,console,output | |
Drill 2: | |
https://jsbin.com/guwuyof/edit?html,css,js,console,output | |
Drill 3: | |
https://jsbin.com/taqexey/edit?css,js,console,output |
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
Start Page: | |
http://codepen.io/chasingSublimity/details/ObZKmx/ | |
Question Page: | |
http://codepen.io/chasingSublimity/details/xRzxVz/ | |
Feedback page: | |
http://codepen.io/chasingSublimity/details/xRzboO/ |
OlderNewer