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 debugging/demo/demo1/demo1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const tomatoes = 'tomatoes';
const chocolate= 'chocolate'yummy';
const chocolate= 'chocolate';
const yogurt = 'yogurt';
const rice = "rice";

Expand Down
2 changes: 1 addition & 1 deletion debugging/demo/demo2/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<html>
<head>
<script type="text/javascript" src="mainScript.js"></script>
<link
rel="stylesheet"
type="text/css"
Expand All @@ -19,5 +18,6 @@ <h1>Javascript Demo Exercise 2</h1>
</div>
<div id="news"></div>
</div>
<script src="script.js"></script>
</body>
</html>
87 changes: 45 additions & 42 deletions debugging/demo/demo2/script.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
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");
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[i].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");
}
})
);
});
10 changes: 5 additions & 5 deletions debugging/exercises/exercise1/exercise1.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
let launchReady = false;
let fuelLevel = 22000;
let thrustOn = false;
let secondsTolaunch = 10;
let secondsToLaunch = 10;
let interval;

const countDown = () => {
console.log(secondsTolaunch--);
switch (secondsTolaunch) {
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...');
Expand All @@ -25,7 +25,7 @@ const countDown = () => {


if (fuelLevel >= 20000) {
console.log(('Fuel level cleared.');
console.log(('Fuel level cleared.'));
launchReady = true;
} else {
console.log('WARNING: Insufficient fuel!');
Expand Down
2 changes: 1 addition & 1 deletion debugging/exercises/exercise2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ <h1>Odin's Library</h1>
</button>
</div>
</div>
<script src="mainscript.js"></script>
<script src="main.js"></script>
</body>
</html>
23 changes: 14 additions & 9 deletions debugging/exercises/exercise2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const book2 = {
read: "No",
};

myLibrary.push(book1;
// Syntax error line 23 - Missing a closing bracket ")". And fixed
myLibrary.push(book1);
myLibrary.push(book2);

render();
Expand All @@ -28,15 +29,16 @@ addButtons.forEach((button) => {
button.addEventListener("click", () => {
formContainer.style.display = "block";
});
};
});
// Syntax error in line 32- Missing a closing bracket ")".

function addDeleteButtons() {
let deleteButtons = document.querySelectorAll(".delete");

deleteButtons.forEach((button) => {
if (button.getAttribute("data-book") == bookNumber) {
//Only add eventListeners to new books
button.addEventListener("clicksss", () => {
button.addEventListener("click", () => {
deleteBook(button.getAttribute("data-book"));
});
}
Expand Down Expand Up @@ -91,9 +93,10 @@ function render() {

row.setAttribute("data-book", bookNumber);

// Reference error in line 99 - titleCella is not defined.
let titleCell = document.createElement("td");
titleCell.append(myLibrary[i].title);
row.append(titleCella);
row.append(titleCell);

let authorCell = document.createElement("td");
authorCell.append(myLibrary[i].author);
Expand All @@ -119,8 +122,10 @@ function render() {
readCell.append(button);
row.append(readCell);

// Reference error in lines 130, 131, 132 - deleteButton is not defined.
// Origin of error is in line 127 Type error -let deleteB.
let deleteCell = document.createElement("td");
let deleteB = document.createElement("button");
let deleteButton = document.createElement("button");
let icon = document.createElement("ion-icon");
icon.setAttribute("name", "trash-outline");
deleteButton.classList.add("delete");
Expand All @@ -132,24 +137,24 @@ function render() {
row.append(deleteCell);

tableBody.insertBefore(row, tableBody.firstChild);

addDeletedButtons();
// Reference error in line 141 - addDeletedButton is undefined.
addDeleteButtons();
addReadButtons();

bookNumber++;
}
}
}

document.getElementById("submit").addEventListener("click", (e) => {
submit.addEventListener("click", (e) => {
e.preventDefault();

let form = document.querySelector("form");
let bookArgs = [];

for (let element of form.elements) {
if (element.id === "read") {
element.checked ? bookArgs.push("No") : bookArgs.push("Yes");
element.checked ? bookArgs.push("Yes") : bookArgs.push("No");
element.checked = false;
} else {
bookArgs.push(element.value);
Expand Down
4 changes: 3 additions & 1 deletion errors/exercise1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if (3 > Math.PI {

// Syntax error line 3.Missing ")" after condition.
if (3 > Math.PI) {
console.log("wait what?");
}
12 changes: 7 additions & 5 deletions errors/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
let charge = function() {
if (sunny) {
useSolarCells();
} else {
promptBikeRide();
// Syntax error in line 8. Missing a "}" after function body.
let charge = function () {
if (sunny) {
useSolarCells();
} else {
promptBikeRide();
}
};
7 changes: 5 additions & 2 deletions errors/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
let ward = "hello";
word.substring(1);
// `ReferenceError: "word" is not defined line 3.
// Line 2 variable "ward" referencing variable word. Made the changes`;
let word = "helloWorld!";
console.log(word.substring(0, 5));
console.log(word.substring(5, word.length));
11 changes: 8 additions & 3 deletions errors/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// `TypeError: numbers.map is not a function`;
let numbers = { a: 13, b: 37, c: 42 };

numbers.map(function (num) {
return num * 2;
});
function double(num) {
return num * 2;
}
let totalArr = [];
totalArr.push(Object.values(numbers));

console.log(totalArr);
5 changes: 3 additions & 2 deletions errors/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
let name;
name.substring(1);
// `TypeError: Cannot read property 'substring' of undefined`;
let name = "MrJerry";
console.log(name.substring(2, name.length));
6 changes: 3 additions & 3 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 -> {
arr.forEach((item, index) => {
console.log(`Item #${index + 1} on the list is ${item}`);
};
});
35 changes: 17 additions & 18 deletions errors/exercise7.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@
// ]

function getTemperatureReport(cities) {
let report = [];
let report = [];

for(let i = 0; i < cities.length(); i++) {
let temperature = temperatureService(city[i]);
report.push(`The temperature in ${city[i]} is ${temperature} degrees`);
}
return report;
for (let i = 0; i < cities.length; i++) {
let temperature = temperatureService(cities[i]);
report.push(`The temperature in ${cities[i]} is ${temperature} degrees`);
}
return report;
}

function temperatureService() {
let temparatureMap = {
'London': 10,
'Paris': 12,
'Barcelona': 17,
'Dubai' 27,
'Mumbai': 29,
'São Paulo': 23
'Lagos': 33


return temparatureMap[city];
function temperatureService(city) {
let temparatureMap = {
London: 10,
Paris: 12,
Barcelona: 17,
Dubai: 27,
Mumbai: 29,
"São Paulo": 23,
Lagos: 33,
};
return temparatureMap[city];
}

let report = getTemperatureReport(["London", "Paris", "São Paulo"]);
Expand Down