Skip to content
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
4 changes: 2 additions & 2 deletions debugging/bank/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ And fix this code!
*/

function isValueFive(n) {
if (n === "5") {
if (n === 5) {
return true
}

return false
}

isValueFive(5)
console.log(isValueFive(5))

9 changes: 5 additions & 4 deletions debugging/bank/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ Can you fix the bug in this function
*/

function getLargestNum(arr) {
let largestNum = 0;
for (let i = 0; i <= arr.length; i++) {
let largestNum = arr[0];
for (let i = 1; i < arr.length; i++) {
console.log(arr[i]);
if (arr[i] > largestNum) {
largestNum = arr[i];
}
}
return largestNum;
}
let arr = [1, 2, 3, 4, 5];
let arr = [5, 2, 3, 4, 1];

getLargestNum(arr)
console.log(getLargestNum(arr));
9 changes: 8 additions & 1 deletion debugging/bank/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ resolve the bug.
*/

function calculateAverage(arr) {
if (arr.length === 0 ) {
return 0;
}
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
return sum / arr.length;
}

let arr = [1, 2, 3, 4, 5];
let arr = [];
console.log(calculateAverage(arr));
arr = [8];
console.log(calculateAverage(arr));
arr = [10,5,1];
console.log(calculateAverage(arr));
2 changes: 1 addition & 1 deletion debugging/bank/findLargest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const findLargest = (numbers) => {
}
return largest;
};
console.log(findLargest([3, 7, 2, 5, 6]));
console.log(findLargest([19, 3, 7, 2, 5, 6]));
2 changes: 1 addition & 1 deletion debugging/bank/sumArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const sumArray = (numbers) => {
}
return total;
};
console.log(sumArray([1, 2, 3]));
console.log(sumArray([1, 2, 3, 4, 5]));
21 changes: 21 additions & 0 deletions debugging/bank/temp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function findMax(someArr) {
// 1. Create a variable to use in comparing the values of the individual elements of the array
let isMax = someArr[0];
// 2. Compare subsequent elements of the array with the max of the array
for (let index = 1; index < arr.length; index++) {
if (isMax < someArr[index]) {
isMax = someArr[index];
}
}
return isMax;
}

let arr = [2, 5, 4, 7, 1, 8];

console.log(findMax(arr));

let somethingElse = [20, 5, 40, 7, 10, 8];

console.log(findMax(somethingElse));

//max, min, average, SD,
9 changes: 9 additions & 0 deletions dom-merge-conflict/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion dom-merge-conflict/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@
},
"scripts": {
"test": "jest"
}
},
"name": "dom-merge-conflict",
"description": "This workshop contains a collection of DOM components. For this workshop, you will be creating branches for refactoring and updating the components and then resolving the merge conflicts that arise. You'll be working in pairs, learning how to handle branching, refactoring, and creating pull requests.",
"version": "1.0.0",
"main": "babel.config.js",
"keywords": [],
"author": "",
"license": "ISC"
}
31 changes: 17 additions & 14 deletions dom-merge-conflict/tasks/buttons-and-counter/src/app.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import { main } from "./main";
import { header } from "./header";

//increments the number in a node's text
function increment(node) {
let current = node.textContent;
node.textContent = Number(current) + 1;
}
// decrements the number in a node's text
function decrement(node) {
let current = node.textContent;
node.textContent = Number(current) - 1;
}

export function App() {
const body = document.createElement("body");

const header = document.createElement("header");
header.innerHTML = `
<h1>Number Counter</h1>
<p>A simple counter. Press increment to increase the count by one.</p>
`;
body.appendChild(header);
body.appendChild(header());
body.appendChild(main());

const main = document.createElement("main");
main.innerHTML = `
<p id="counter" data-testid="counter">0</p>
<button id="increment">Increment</button>
`;
body.appendChild(main);
const incrementButton = body.querySelector("#increment");
const decrementButton = body.querySelector("#decrement");

const button = body.querySelector("#increment");
const counter = body.querySelector("#counter");
button.addEventListener("click", () => {

incrementButton.addEventListener("click", () => {
increment(counter);
});

decrementButton.addEventListener("click", () => {
decrement(counter);
});
return body;
}
10 changes: 10 additions & 0 deletions dom-merge-conflict/tasks/buttons-and-counter/src/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function header() {
const header = document.createElement("header");
header.innerHTML = `
<h1>Number Counter</h1>
<p>A simple counter. Press increment to increase the count by one.</p>
<p>A simple counter. Press decrement to decrease the count by one.</p>
`;

return header;
}
10 changes: 10 additions & 0 deletions dom-merge-conflict/tasks/buttons-and-counter/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function main() {
const main = document.createElement("main");
main.innerHTML = `
<p id="counter" data-testid="counter">0</p>
<button id="increment">Increment</button>
<button id="decrement">Decrement</button>
`;

return main;
}
6 changes: 3 additions & 3 deletions dom-merge-conflict/tasks/buttons-and-counter/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("button and counter", () => {
expect(getByTestId(container, "counter")).toHaveTextContent(/^2$/);
});

describe.skip("decrement button", () => {
// describe.skip("decrement button", () => {
test("pressing Decrement decreases the counter", () => {
const button = getByRole(container, "button", {
name: "Decrement",
Expand All @@ -49,8 +49,8 @@ describe("button and counter", () => {

test("contains description paragraph with mention of 'decrement' in header", () => {
expect(
container.querySelector("header").querySelector("p")
container.querySelector("header").querySelectorAll("p")[1]
).toHaveTextContent(/decrement/i);
});
});
});
//});
2 changes: 1 addition & 1 deletion objects/100.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const person3 = person2;

person3.location = "Manchester";

console.log(person1.name);
console.log(person1.name); //
console.log(person2["name"]);
console.log(person1.id_number > person2["id_number"]);
console.log(person1.job);
Expand Down
6 changes: 3 additions & 3 deletions objects/200.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ const person = {
"id_number" = 9,
};

console.assert(person.name === "Jemima");
console.assert(person.location === "Glasgow");
console.assert(person.id_number === 9);
console.assert(person.name === "Jemima"); //True
console.assert(person.location === "Glasgow"); //Undefined
console.assert(person.id_number === 9); //True
6 changes: 3 additions & 3 deletions objects/300.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Fix anything that needs fixing.

function checkLivesNearCYF(person) {
console.log(person);
const cyfLocations = ["Birmingham", "Cape Town", "Glasgow", "London", "Manchester"];
return cyfLocations.includes(person.location);
}
Expand All @@ -19,6 +20,5 @@ const sayed = {
"city": "Edinburgh",
"focus": "SQL",
}

console.assert(checkLivesNearCYF(mo));
console.assert(!checkLivesNearCYF(sayed));
console.assert(checkLivesNearCYF(mo)); //True
console.assert(!checkLivesNearCYF(sayed)); //False
Loading