Skip to content
Open

01 #4

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 30 additions & 36 deletions 00-prep/lab/1-ES6-practice/arrow-functions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const theOldWay = function(course) {
};

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log('The old way:', theOldWay('Code 301'));
console.log('The old way:', theOldWay('Code 301'));


// STEP 2
Expand All @@ -18,7 +18,7 @@ const theNewWay = (course) => {
};

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log('The new way:', theNewWay('Code 301'));
console.log('The new way:', theNewWay('Code 301'));


// STEP 3
Expand All @@ -28,7 +28,7 @@ const withoutParens = course => {
};

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log('Without parens:', withoutParens('Code 301'));
console.log('Without parens:', withoutParens('Code 301'));


// STEP 4
Expand All @@ -38,7 +38,7 @@ const withoutParens = course => {
const oneLiner = course => `I cam currently enrolled in ${course}`;

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log('As a one-liner:', oneLiner('Code 301'));
console.log('As a one-liner:', oneLiner('Code 301'));


// STEP 5
Expand All @@ -49,7 +49,7 @@ const add = function(num1, num2) {
};

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log('Let\'s do some math:', add(4, 5));
console.log('Let\'s do some math:', add(4, 5));


// STEP 6
Expand All @@ -58,7 +58,7 @@ const add = function(num1, num2) {
const addOneLiner = (num1, num2) => `${num1} + ${num2} = ${num1 + num2}`;

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log('Add as a one-liner:', addOneLiner(4, 5));
console.log('Add as a one-liner:', addOneLiner(4, 5));


// STEP 7
Expand All @@ -70,7 +70,7 @@ const multiLiner = word => {
};

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log('Multi-line arrow function:', multiLiner('hello'));
console.log('Multi-line arrow function:', multiLiner('hello'));


// STEP 8
Expand All @@ -85,7 +85,7 @@ const oldObject = function(array) {
};

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log('Hello from the old object function', oldObject(['hi', 'hello', 'are you there?']));
console.log('Hello from the old object function', oldObject(['hi', 'hello', 'are you there?']));


// STEP 9
Expand All @@ -98,52 +98,48 @@ const newObject = array => ({
});

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log('Hello from the new object function', newObject(['hi', 'hello', 'are you there?']));
console.log('Hello from the new object function', newObject(['hi', 'hello', 'are you there?']));


// STEP 10
// Uncomment the console.log lines to view the output of each function in the browser console.
// Refactor each function into an arrow function.
// Write your solutions on a single line wherever possible.
// Write your solutions on a single line wherever possible.



let sum = function(a, b, c, d) {
return a + b + c + d;
};
let sum = (a, b, c, d) => ( a + b + c + d);

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log(sum(1, 2, 3, 4));
console.log(sum(1, 2, 3, 4));


let objectLit = function() {
return {
key1: 'value1',
key2: 'value2',
key3: 'value3',
};
};
let objectLit = () => ({
key1: 'value1',
key2: 'value2',
key3: 'value3'
});

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log(objectLit());
console.log(objectLit());


let sumAndProduct = function(a, b) {
let sumAndProduct = (a, b) => {
let sum = a + b;
let product = a * b;
return [sum, product];
};

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log(sumAndProduct(3, 9));
console.log(sumAndProduct(3, 9));


let message = function(name) {
return `Hello, ${name}!`;
};

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log(message('Allie'));
console.log(message('Allie'));


let Student = function(name, age, hometown) {
Expand All @@ -156,7 +152,7 @@ let joe = new Student('Joe', 'Schmoe', 100);

// TODO: Uncomment the following line of code to see the output in the browser console
// Note that the arrow function will cause this code to break!
// console.log(joe);
console.log(joe);


Student.prototype.greeting = function() {
Expand All @@ -165,15 +161,13 @@ Student.prototype.greeting = function() {

// TODO: Uncomment the following line of code to see the output in the browser console
// Note that the arrow function will cause this method to break!
// console.log(joe.greeting());
console.log(joe.greeting());


Student.courseName = function() {
return 'This student is enrolled in Code 301.';
};
Student.courseName = () => ('This student is enrolled in Code 301.');

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log(Student.courseName());
console.log(Student.courseName());



Expand All @@ -184,17 +178,17 @@ Student.prototype.scope = function() {
};

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log(joe.scope());
console.log(joe.scope());

Student.prototype.scopeArrow = () => console.log(this);

// TODO: Uncomment the following line of code to see the output in the browser console
// console.log(joe.scopeArrow());
console.log(joe.scopeArrow());

// TODO: Write a COMMENT below to answer the following questions.
// 1. What is "this" when joe.scope() is invoked?
//
//"this" is an object when joe.scope() is invoked; it is the student object with properties of name, age, and hometoown
// 2. What is "this" when joe.scopeArrow() is invoked?
//
//"this" is undefined with joe.scopeArrow() becuase arrow functions do not bind "this" so the context of "this" goes up to global window object
// 3. Explain why "this" is different when an arrow function is used.
//
//arrow functions do not bind this so "this" is becomes part of global window object and in that setting, the variable "this" is not defined
53 changes: 26 additions & 27 deletions 00-prep/lab/1-ES6-practice/let-const/js/app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
'use strict';

var names = ['bag', 'banana', 'bathroom', 'boots', 'breakfast', 'bubblegum', 'chair', 'cthulhu', 'dog-duck', 'dragon', 'pen', 'pet-sweep', 'scissors', 'shark', 'sweep', 'tauntaun', 'unicorn', 'usb', 'water-can', 'wine-glass'];
const names = ['bag', 'banana', 'bathroom', 'boots', 'breakfast', 'bubblegum', 'chair', 'cthulhu', 'dog-duck', 'dragon', 'pen', 'pet-sweep', 'scissors', 'shark', 'sweep', 'tauntaun', 'unicorn', 'usb', 'water-can', 'wine-glass'];

var leftImage = document.getElementById('left');
var centerImage = document.getElementById('center');
var rightImage = document.getElementById('right');
const leftImage = document.getElementById('left');
const centerImage = document.getElementById('center');
const rightImage = document.getElementById('right');

var allProducts = [];
var container = document.getElementById('image_container');
var viewed = [];
var labels = [];
var pics = [leftImage, centerImage, rightImage];
var list = document.getElementById('productlist');
var totalClicks = 0;
var views = [];
var votes = [];
let allProducts = [];
const container = document.getElementById('image_container');
const viewed = [];
const labels = [];
const pics = [leftImage, centerImage, rightImage];
const list = document.getElementById('productlist');
let totalClicks = 0;
const views = [];
const votes = [];

function Product(name) {
this.name = name;
this.path = 'img/' + name + '.jpg';
this.path = `img ${name} .jpg`;
this.votes = 0;
this.views = 0;
allProducts.push(this);
Expand All @@ -30,18 +30,17 @@ function makeRandom() {

function displayPics(){
while(viewed.length < 6){
var rando = makeRandom();
const rando = makeRandom();
while(!viewed.includes(rando)){
viewed.push(rando);
}
}
console.log(rando);
// TODO: In a sentence or two, explain why the previous line of code threw an error when we changed the variable declaration from `var to `let`.
// PUT YOUR RESPONSE IN THIS COMMENT
// TODO: In a sentence or two, explain why the previous line of code threw an error when we changed the variable declaration from `const to `const`.
// The variable const is scoped to a local code block and is not defined outside of the function displayPics();
console.log(viewed);

for (var i = 0; i < 3; i++){
var temp = viewed.shift();
for (let i = 0; i < 3; i++){
const temp = viewed.shift();
pics[i].src = allProducts[temp].path;
pics[i].id = allProducts[temp].name;
allProducts[temp].views += 1;
Expand All @@ -59,10 +58,10 @@ function handleClick(event) {
showList();
makeChart();
}
for(var i = 0; i < names.length; i++){
for(let i = 0; i < names.length; i++){
if(event.target.id === allProducts[i].name) {
allProducts[i].votes += 1;
console.log(event.target.id + ' has ' + allProducts[i].votes + ' votes in ' + allProducts[i].views + ' views');
console.log(`${event.target.id} has ${allProducts[i].votes} votes in ${allProducts[i].views} views`);
}
}
localStorage.busmall = JSON.stringify(allProducts);
Expand All @@ -71,9 +70,9 @@ function handleClick(event) {
}

function showList() {
for(var i = 0; i < allProducts.length; i++) {
var liEl = document.createElement('li');
liEl.textContent = allProducts[i].name + ' has ' + allProducts[i].votes + ' votes in ' + allProducts[i].views + ' views';
for(let i = 0; i < allProducts.length; i++) {
const liEl = document.createElement('li');
liEl.textContent = `${allProducts[i].name} has ${allProducts[i].votes} votes in ${allProducts[i].views} views`;
list.appendChild(liEl);
}
}
Expand All @@ -88,7 +87,7 @@ function makeChartData(){

function makeChart(){
makeChartData();
var ctx = document.getElementById('chartypants').getContext('2d');
const ctx = document.getElementById('chartypants').getContext('2d');
new Chart(ctx, { //eslint-disable-line
type: 'bar',
data: {
Expand Down Expand Up @@ -128,7 +127,7 @@ if(localStorage.busmall){
allProducts = JSON.parse(localStorage.busmall);
} else {
console.log('There is no local storage data; initialize app by creating instances');
for(var i = 0; i < names.length; i++) {
for(let i = 0; i < names.length; i++) {
new Product(names[i]);
}
}
Expand Down
6 changes: 5 additions & 1 deletion 00-prep/lab/2-SMACSS-practice/starter-code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<meta charset="utf-8">
<title>Choco Pizza</title>
<link rel="stylesheet" href="styles/reset.css">
<link rel="stylesheet" href="styles/style.css">
<link rel="stylesheet" href="styles/base.css">
<link rel="stylesheet" href="styles/layout.css">
<link rel="stylesheet" href="styles/modules.css">


</head>
<body>
<header>
Expand Down
57 changes: 57 additions & 0 deletions 00-prep/lab/2-SMACSS-practice/starter-code/styles/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@import url('https://fonts.googleapis.com/css?family=Abel|Oswald:700|Yellowtail|Patrick+Hand');
* {
font-family: times;
}

body {
background: #fff;
}

h2 {
font-family: 'Oswald', sans-serif;
font-size: 2.5em;
}

hr {
background-image: url('img/hr-img.gif');
}

main p {
color: #333;
font-size: 1.2em;
line-height: 1.3em;
text-indent: 30px;
}

input {
font-family: 'Patrick Hand', cursive;
}

aside h3 {
font-size: 1.6em;
color: #555;
}

aside p {
text-indent: 0;
}

aside button {
font-family: 'Abel', sans-serif;
text-transform: uppercase;
background: #b8705a;
color: #fff;
font-size: 1.2em;
border: none;
}

section hr {
border-bottom: 1px solid #eee;
}


footer section p{
line-height: 1.5em;
text-align: center;
color: #aaa;
}
Loading