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
// 'Promise' --> the guarantee that some callback is running and doing things | |
// and that it will come back to you when it's done, | |
// either by succeeding or by failing. | |
const promise = new Promise((resolve, reject) => { | |
setTimeout(() => resolve('done!'), 2000); // increase this with 1 millisecond, and then the rejection happens before the resolution :o! | |
setTimeout(() => reject('failed'), 2000); | |
}); | |
promise |
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
root = true | |
[*] | |
charset = utf-8 | |
indent_style = space | |
indent_size = 2 | |
end_of_line = lf | |
insert_final_newline = true | |
trim_trailing_whitespace = true |
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
// Arrow functions | |
let addFunction = function(a, b) { | |
return a + b; | |
} | |
// these are different ways to write functions, with only very minor differences | |
addFunction = function(a, b) { return a + b }; | |
addFunction = (a, b) => { return a + b }; | |
addFunction = (a, b) => a + b ; |
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
/** | |
* | |
* 1) OBJECTS YAY!!! | |
* | |
*/ | |
const animals = { | |
'turtle': '🐢', | |
'unicorn': '🦄', | |
} |
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
// FIZZBUZZ Simple | |
for (var i = 1; i <= 100; i++) { | |
var fizz = 3; | |
var buzz = 5; | |
if (i % 3 === 0 && i % 5 === 0){ | |
console.log('FizzBuzz'); | |
} else if (i % 3 === 0) { | |
console.log('Fizz'); | |
} else if (i % 5 === 0) { |
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
let choices = ['paper', 'rock', 'scissors']; | |
let playerChoice = prompt('What will you play? rock, paper or scissors?'); | |
let opponentChoice = choices[Math.floor(Math.random() * 3)]; | |
if (playerChoice === opponentChoice) { | |
alert('Opponent had: ' + opponentChoice + '. DRAW!'); | |
} else if (playerChoice === 'paper' && opponentChoice === 'rock') { | |
alert('Opponent had: ' + opponentChoice + '. YOU WON :)!'); | |
} else if (playerChoice === 'paper' && opponentChoice === 'scissors') { | |
alert('Opponent had: ' + opponentChoice + '. YOU LOST :(!'); |
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
alert('Welcome to the Rock Paper and Scissors game!'); | |
playGame(); | |
function playGame() { | |
var choice = prompt('What will you play? rock, paper or scissors?'); | |
var opponentChoice = Math.ceil(Math.random() * 3); | |
switch(opponentChoice) { | |
case 1: opponentChoice = 'paper'; | |
case 2: opponentChoice = 'rock'; |