From 67647302ecc3c94abcaf292cc08af303ada5eacf Mon Sep 17 00:00:00 2001 From: Feddly Jeanniton Date: Mon, 1 Mar 2021 21:00:47 -0500 Subject: [PATCH 1/2] Problems Solved --- Day01/Problem01.js | 138 ++++++++++++++++++++++++++--------------- Day01/Problem01_org.js | 66 ++++++++++++++++++++ Day01/Untitled-1.txt | 41 ++++++++++++ 3 files changed, 195 insertions(+), 50 deletions(-) create mode 100644 Day01/Problem01_org.js create mode 100644 Day01/Untitled-1.txt diff --git a/Day01/Problem01.js b/Day01/Problem01.js index 6ad3c39..df70f1a 100644 --- a/Day01/Problem01.js +++ b/Day01/Problem01.js @@ -1,58 +1,96 @@ class Problem { - /** - * Have the wordCount(input) take the str string parameter being passed - * and return the number of words the string contains - * (e.g. "Never eat shredded wheat or cake" would return 6). Words will be - * separated by single spaces. - */ - wordCount(input) { - // code goes here - return null; - } - - /** - * Have the function LetterCapitalize(str) take the str parameter being passed and capitalize the first - letter of each word. Words will be separated by only one space. - * - */ - letterCapitalize(str) { - return null; + * Have the wordCount(input) take the str string parameter being passed + * and return the number of words the string contains + * (e.g. "Never eat shredded wheat or cake" would return 6). Words will be + * separated by single spaces. + */ +wordCount(input) { + // code goes here + let string = input.split(' '); + let wordLength = string.length; + return wordLength; +} +/** + * Have the function LetterCapitalize(str) take the str parameter being passed and capitalize the first + letter of each word. Words will be separated by only one space. +* +*/ +// letterCapitalize(string) { +// return string.charAt(0).toUpperCase() + string.slice(1); +// } +letterCapitalize(str) { +// create a variable to contain output +let output = "" +// create a loop to go through the string +for(let i = 0; i < str.length; i ++){ +// capitalize first index + if(i === 0){ + output += str[i].toUpperCase() +// add to variable } - - - - /** - * Have the function firstReverse(String input) take the input parameter being passed and - * return the string in reversed order. For example: if the input string is "Hello World and Coders" then your - * program should return the string sredoC dna dlroW olleH. - */ - - firstReverse(input){ - return null; + else if (str[i-1] === " "){ +// capitalize the index after each space +// add to variable + output += str[i].toUpperCase() } - - /** - * Have the longestWord(String input) take the input parameter being passed and return the - * largest word in the string. If there are two or more words that are the same length, - * return the first word from the string with that length. Ignore punctuation and assume - * input will not be empty. - */ - longestWord(input) { - // code goes here - return null; + else { + output += str[i] } - - /** - * Have the swapCase(String input) take the input parameter and swap the case of each - * character. For example: if str is "Hello World" the output should be hELLO wORLD. - * Let numbers and symbols stay the way they are. - */ - swapCase(str) { - // code goes here - return null; +} +// return the output +return output; +} +// Line 53 - 56 is another way to run letter Capitalize test case +// letterCapitalize(string) { +// return string.replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase()))); +// } +/** + * Have the function firstReverse(String input) take the input parameter being passed and + * return the string in reversed order. For example: if the input string is "Hello World and Coders" then your + * program should return the string sredoC dna dlroW olleH. + */ +firstReverse(input){ + let splitString = input.split(''); + let reverseArray = splitString.reverse(); + let joinArray = reverseArray.join(''); + return joinArray; +} +/** + * Have the longestWord(String input) take the input parameter being passed and return the + * largest word in the string. If there are two or more words that are the same length, + * return the first word from the string with that length. Ignore punctuation and assume + * input will not be empty. + */ +longestWord(input) { + var str = input.split(/[^a-zA-Z]/); // splits string into words & ignores non-letters + var longest = 0; + var word = str; + for (var i = 0; i <= str.length - 1; i++) { // steps thru array & adjusts count to begin at 0 + if (longest < str[i].length) { // compares current longest with word in the array + longest = str[i].length; // longest word is replaced with new longest word + word = str[i]; // word is now the longest word + } + } + return word; +} +/** + * Have the swapCase(String input) take the input parameter and swap the case of each + * character. For example: if str is "Hello World" the output should be hELLO wORLD. + * Let numbers and symbols stay the way they are. + */ +swapCase(str) { + // code goes here + var newLetters = ""; +for(var i = 0; i= 0; i--){ + let character - sentence + } + return null; + } + + /** + * Have the longestWord(String input) take the input parameter being passed and return the + * largest word in the string. If there are two or more words that are the same length, + * return the first word from the string with that length. Ignore punctuation and assume + * input will not be empty. + */ + + + + longestWord(input) { + // code goes here + return null; + } + + /** + * Have the swapCase(String input) take the input parameter and swap the case of each + * character. For example: if str is "Hello World" the output should be hELLO wORLD. + * Let numbers and symbols stay the way they are. + */ + swapCase(str) { + // code goes here + return null; + } + +} + +module.exports = Problem; \ No newline at end of file diff --git a/Day01/Untitled-1.txt b/Day01/Untitled-1.txt new file mode 100644 index 0000000..3ad8a92 --- /dev/null +++ b/Day01/Untitled-1.txt @@ -0,0 +1,41 @@ +et pokedex = document.getElementById("pokedex"); +console.log(pokedex); +let url = "https://pokeapi.co/api/v2/pokemon/"; +let fetchPokemon = () => { + const promises = []; + for (let i = 1; i <= 898; i++) { + // console.log(url + i); + promises.push(fetch(url + i).then((res) => res.json())); + } + Promise.all(promises).then(results => { + const pokemon = results.map((data) => ({ + name: data.name, + id: data.id, + image: data.sprites['front_shiny'], + type: data.types[0].type.name + // type: data.types.map((type) => type.type.name).join(',') + })); + displayPokemon(pokemon); + }); +}; +let thisPokemon; +let displayPokemon = (pokemon) => { + console.log(pokemon.type); + const pokemonHTMLString = pokemon.map( + (pokeman) => ` +
+ +

${pokeman.id}. ${pokeman.name}

+

Type: ${pokeman.type}

+
+ `).join(''); + pokedex.innerHTML = pokemonHTMLString; +// return cardColor(); +}; +// card.classList.add('card', `${​​​​​pokeman.types[0].type.name}​​​​​`, 'font-weight-bold'); +function cardColor(){ + if (pokeman.type === 'grass') { + document.getElementsByClassName("card")[0].style.backgroundColor="blue"; + } +}; +fetchPokemon(); \ No newline at end of file From 9a43622581231d81fc1389aea1a3abe07f46ac6b Mon Sep 17 00:00:00 2001 From: Feddly Jeanniton Date: Mon, 1 Mar 2021 21:01:57 -0500 Subject: [PATCH 2/2] Problems Solved --- Day01/Problem01_org.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Day01/Problem01_org.js b/Day01/Problem01_org.js index 68c917b..a08eb3e 100644 --- a/Day01/Problem01_org.js +++ b/Day01/Problem01_org.js @@ -32,7 +32,7 @@ class Problem { let message = ""; for (let i = sentence.length - 1; i>= 0; i--){ - let character - sentence + let character = sentence } return null; }