Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"no-redeclare": ["warn"],
"no-undef": ["warn"]
}
}
}
59 changes: 33 additions & 26 deletions debugging/demo/demo1/demo1.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
const tomatoes = 'tomatoes';
const chocolate= 'chocolate'yummy';
const yogurt = 'yogurt';
const tomatoes = "tomatoes";
const chocolate = "chocolate yummy";
const yogurt = "yogurt";
const rice = "rice";

const fridge =[{ item: tomatoes, quantity: 5},
{ item: chocolate, quantity: 1},
{ item: yogurt, quantity: 5}];
const fridge = [
{ item: tomatoes, quantity: 5 },
{ item: chocolate, quantity: 1 },
{ item: yogurt, quantity: 5 },
];

const wantedList = [{ item: tomatoes, quantity: 4},
{ item: chocolate, quantity: 10},
{ item: yogurt, quantity: 2}]
const wantedList = [
{ item: tomatoes, quantity: 4 },
{ item: chocolate, quantity: 10 },
{ item: yogurt, quantity: 2 },
];

const shoppingList = (fridge, wantedList) => {
return wantedList.map(groceryWantedList => {
let groceryFridge = fridge.find( gf => gf.item === groceryWantedList.item);
if (groceryFridge===null){
return groceryWantedList;
const shoppingList = (fridge, wantedList) => {wantedList
.map((groceryWantedList) => {
let groceryFridge = fridge.find(
(gf) => {
return gf.item === groceryWantedList.item;
}
);
if (groceryFridge === null) {
return groceryWantedList;
} else {
if (groceryFridge.quantity < groceryWantedList.quantity) {
return {
item: groceryWantedList.item,
quantity: groceryWantedList.quantity - groceryFridge.quantity,
};
} else {
if (groceryFridge.quantity < groceryWantedList.quantity){
return {
item: groceryWantedList.item,
quantity: groceryWantedList.quantity - groceryFridge.quantity
};
}
else{
return null;
}
}
}).filter(item => item !== null);
};
})
.filter((item) => item !== null);

shoppingList (fridge, wantedList).forEach( (item) => {
console.log (`${item.item}: ${item.quantity}`);
})
shoppingList(fridge, wantedList).forEach((item) => {
console.log(`${item.item}: ${item.quantity}`);
});
2 changes: 1 addition & 1 deletion debugging/demo/demo2/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<script type="text/javascript" src="mainScript.js"></script>
<script type="text/javascript" src="script.js"></script>
<link
rel="stylesheet"
type="text/css"
Expand Down
90 changes: 48 additions & 42 deletions debugging/demo/demo2/script.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
document.addEventListener("DOMContentLoaded", ( ) => {
var data = [
{
text: 'Overshadowing #UNGA is the big question: Will Obama and Rouhani meet?',
href: 'https://twitter.com/cnnbrk/status/382528782738800641'
},
{
text: "Marine's family hopes visiting Iranian president will help free their son",
href: 'https://twitter.com/cnnbrk/status/382519683053649920'
},
{
text: 'Obama addresses United Nations.',
href: 'https://twitter.com/cnnbrk/status/382507500903202817'
},
{
text: '',
href: 'https://twitter.com/CNNMoney/status/382497891723804672'
},
{
text: "If you're seeing this as a button, congratulations!",
href: 'http://twitter.com'
}
];
for (var i = 0; i<data.length; i++) {
if (data.text) {
const pElement = document.createElement("p");
const button = document.createElement("button");
button.type = "button"
button.classList.add(["btn", "btn-default"]);
button.setAttribute('data-href', data.href);
button.innerText = data.text;
pElement.appendChild(button);
document.querySelector('#news').appendChild(pElement);
}
}
const buttons = document.querySelectorAll("button");
debugger;
document.addEventListener("DOMContentLoaded", () => {
var data = [
{
text:
"Overshadowing #UNGA is the big question: Will Obama and Rouhani meet?",
href: "https://twitter.com/cnnbrk/status/382528782738800641",
},
{
text:
"Marine's family hopes visiting Iranian president will help free their son",
href: "https://twitter.com/cnnbrk/status/382519683053649920",
},
{
text: "Obama addresses United Nations.",
href: "https://twitter.com/cnnbrk/status/382507500903202817",
},
{
text: "",
href: "https://twitter.com/CNNMoney/status/382497891723804672",
},
{
text: "If you're seeing this as a button, congratulations!",
href: "http://twitter.com",
},
];
for (var i = 0; i < data.length; i++) {
if (data[i].text) {
const pElement = document.createElement("p");
const button = document.createElement("button");
button.type = "button";
button.classList.add(["btn", "btn-default"]);
button.setAttribute("data-href", data.href);
button.innerText = data[i].text;
pElement.appendChild(button);
document.querySelector("#news").appendChild(pElement);
}
}
const buttons = document.querySelectorAll("button");

buttons.forEach(el => el.addEventListener('click', evt => {
const ctrl = evt.target;
if (!ctrl.getAttribute('data-href')) {
document.location = ctrl.getAttribute('data-href');
}}))
})
buttons.forEach((el) =>
el.addEventListener("click", (evt) => {
const ctrl = evt.target;
if (!ctrl.getAttribute("data-href")) {
document.location = ctrl.getAttribute("data-href");
}
})
);
});
20 changes: 9 additions & 11 deletions debugging/exercises/exercise1/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@ const countDown = () => {
console.log(secondsTolaunch--);
switch (secondsTolaunch) {
case 7:
console.log('Close Davy Jones' Locker..');
console.log("Close Davy Jones Locker..");
break;
case 3:
console.log('Ignition...');
console.log("Ignition...");
break;
case 0:
console.log('Liftoff!');
console.log("Liftoff!");
clearInterval(interval);
break;
default:
break;
}

};


if (fuelLevel >= 20000) {
console.log(('Fuel level cleared.');
launchReady = true;
console.log("Fuel level cleared.");
launchReady = true;
} else {
console.log('WARNING: Insufficient fuel!');
launchReady = false;
console.log("WARNING: Insufficient fuel!");
launchReady = false;
}
if (launchReady){
interval = setInterval(countDown, 1000)
if (launchReady) {
interval = setInterval(countDown, 1000);
}
2 changes: 1 addition & 1 deletion debugging/exercises/exercise2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h1>Odin's Library</h1>
</div>
<div id="desktop-button-container">
<button type="button" id="add-button-desktop" class="add-button">
Add book
Add new book
</button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions debugging/exercises/exercise2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const book2 = {
read: "No",
};

myLibrary.push(book1;
myLibrary.push(book1);
myLibrary.push(book2);

render();
Expand All @@ -28,7 +28,7 @@ addButtons.forEach((button) => {
button.addEventListener("click", () => {
formContainer.style.display = "block";
});
};
});

function addDeleteButtons() {
let deleteButtons = document.querySelectorAll(".delete");
Expand Down
4 changes: 2 additions & 2 deletions errors/exercise1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if (3 > Math.PI {
console.log("wait what?");
if (3 > Math.PI) {
console.log("wait what?");
}
11 changes: 6 additions & 5 deletions errors/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let charge = function() {
if (sunny) {
useSolarCells();
} else {
promptBikeRide();
let charge = function (sunny) {
if (sunny) {
useSolarCells();
} else {
promptBikeRide();
}
};
2 changes: 1 addition & 1 deletion errors/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let ward = "hello";
let word = "hello";
word.substring(1);
8 changes: 4 additions & 4 deletions errors/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let numbers = { a: 13, b: 37, c: 42 };
let numbers = [ {a: 13}, {b: 37}, {c: 42} ];

numbers.map(function (num) {
return num * 2;
});
numbers.map( (num) {
return num * 2;
};)
2 changes: 1 addition & 1 deletion errors/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let name;
let name = "";
name.substring(1);
8 changes: 4 additions & 4 deletions errors/exercise6.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Item #2 on the list is eggs
// Item #3 on the list is milk

let arr ["bread", eggs", "milk"];
let arr = ["bread", "eggs", "milk"];

items.forEach(item, index -> {
console.log(`Item #${index + 1} on the list is ${item}`);
};
arr.forEach((items, index) => {
console.log(`Item #${index} on the list is ${items}`);
});