diff --git a/challenges/unit-testing/writing-tests/largest-number/largest-number.js b/challenges/unit-testing/writing-tests/largest-number/largest-number.js index 4036dd7..0f668cd 100644 --- a/challenges/unit-testing/writing-tests/largest-number/largest-number.js +++ b/challenges/unit-testing/writing-tests/largest-number/largest-number.js @@ -1,3 +1,4 @@ +let arr = [12, 33, 22, 45, 88, 54]; function getLargestNumber(array) { let largestNumber = array[0]; for (let i = 0; i < array.length; i++) { @@ -5,7 +6,9 @@ function getLargestNumber(array) { largestNumber = array[i]; } } + console.log(largestNumber); + console.log(array) return largestNumber; } - +getLargestNumber(arr); module.exports = getLargestNumber; diff --git a/challenges/unit-testing/writing-tests/largest-number/largest-number.test.js b/challenges/unit-testing/writing-tests/largest-number/largest-number.test.js index ce67420..959333e 100644 --- a/challenges/unit-testing/writing-tests/largest-number/largest-number.test.js +++ b/challenges/unit-testing/writing-tests/largest-number/largest-number.test.js @@ -2,8 +2,11 @@ let getLargestNumber = require("./largest-number"); test("returns largest number in array", function () { // Arrange + let arr = [12, 33, 22, 45, 88, 54]; // Act + let expected = 88; // Assert + expect(getLargestNumber(arr)).toBe(expected); }); // example diff --git a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.js b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.js index 6f4e06b..89fc2cc 100644 --- a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.js +++ b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.js @@ -1,13 +1,13 @@ let removeVowels = require("./remove-vowels"); - +let arr = ["Irina", "Etza", "Daniel"]; function removeVowelsFromWords(words) { let result = words.map(function (word) { return removeVowels(word); }); - + console.log(result); return result; } - +removeVowelsFromWords(arr); module.exports = removeVowelsFromWords; /* diff --git a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.test.js b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.test.js index ee739e2..c5f113d 100644 --- a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.test.js +++ b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.test.js @@ -2,8 +2,11 @@ let removeVowelsFromWords = require("./remove-vowels-in-array"); test("remove vowels from all words in array", function () { // Arrange + let array = ["Irina", "Etza", "Daniel"]; // Act + let expected = ["rn", "tz", "Dnl"]; // Assert + expect(removeVowelsFromWords(array)).toEqual(expected); }); // example diff --git a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels.js b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels.js index e5bb67b..209e68a 100644 --- a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels.js +++ b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels.js @@ -5,19 +5,19 @@ function removeVowels(word) { characters.forEach(function (character) { if ( - character !== "a" && - character !== "o" && - character !== "i" && - character !== "e" && - character !== "u" + character.toLowerCase() !== "a" && + character.toLowerCase() !== "o" && + character.toLowerCase() !== "i" && + character.toLowerCase() !== "e" && + character.toLowerCase() !== "u" ) { result.push(character); } }); - + console.log(result.join("")) return result.join(""); } - +removeVowels("samuel"); module.exports = removeVowels; /* diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html new file mode 100644 index 0000000..a9f5183 --- /dev/null +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,18 @@ + + + + + + + XKCD Comic Viewer + + + + + + + + + + + \ No newline at end of file diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js new file mode 100644 index 0000000..21e01a9 --- /dev/null +++ b/fetch/programmer-humour/script.js @@ -0,0 +1,27 @@ + +let myData; + +async function fetchData() { + try{ + const response = await fetch("https://xkcd.now.sh/?comic=latest") + + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + + myData = await response.json() + //console.log(`${JSON.stringify(myData)} this is api`) + let section = document.body; + const image = document.createElement("img"); + image.src = myData.img; + image.alt = myData.alt; + section.appendChild(image); + } + catch(error) { + console.error("an error happened", error.message); + alert("Something went wrong. Please try again later."); + } + +} + +fetchData() diff --git a/fetch/programmer-humour/style.css b/fetch/programmer-humour/style.css new file mode 100644 index 0000000..2a24e61 --- /dev/null +++ b/fetch/programmer-humour/style.css @@ -0,0 +1,4 @@ +img{ + width: 500px; + height: 500px; +} \ No newline at end of file