Skip to content

Instantly share code, notes, and snippets.

View jorenbroekema's full-sized avatar
🦎
Bringing Style-Dictionary to new heights!

Joren Broekema jorenbroekema

🦎
Bringing Style-Dictionary to new heights!
View GitHub Profile
// '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
@jorenbroekema
jorenbroekema / .editorconfig
Created September 6, 2019 14:38
Editor config
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
@jorenbroekema
jorenbroekema / lesson5.js
Last active March 18, 2019 12:25
Lesson Arrow functions, promises and async / await
// 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 ;
@jorenbroekema
jorenbroekema / lesson.js
Last active March 5, 2019 21:11
Showcasing JS Objects, functions, template literals and arrow functions
/**
*
* 1) OBJECTS YAY!!!
*
*/
const animals = {
'turtle': '🐢',
'unicorn': '🦄',
}
@jorenbroekema
jorenbroekema / fizzbuzz.js
Created February 3, 2019 15:21
Quick fizzbuzz examples different levels
// 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) {
@jorenbroekema
jorenbroekema / simpleRPS.js
Last active February 3, 2019 14:57
simple Rock paper scissors
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 :(!');
@jorenbroekema
jorenbroekema / rps.js
Created February 3, 2019 14:48
Rock paper scissors prompt game
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';