From 862df7c7b1b64b19b5893bc0e46d9e25df150ba8 Mon Sep 17 00:00:00 2001 From: "J. J. YOUNG" <41083436+himslf@users.noreply.github.com> Date: Mon, 20 Sep 2021 20:52:18 -0400 Subject: [PATCH 1/2] Obligatory Save/Upload --- string.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/string.js b/string.js index 07d52da..1f86563 100644 --- a/string.js +++ b/string.js @@ -6,12 +6,19 @@ // DrEvil(1000000): 1000000 dollars (pinky) // answer below: +function DrEvil (amount) { + if (amount == 1000000) { + console.log(amount + " dollars! (pinky)"); + } else { + console.log(amount + " dollars."); + } +}; +DrEvil(1421094); // returns 1421094 dollars. +DrEvil(1000000); // 1000000 dollars! (pinky) - - - +console.log("---------+---------") //Create a function called mixUp //It should take in two stings, and return the concatenation of the two strings(separated by a space) //slicing out and swapping the first 2 characters of each. You can assume that the strings are at least 2 characters long. @@ -20,22 +27,31 @@ //mixUp('dog', 'dinner'): 'dig donner' //write answer below +function mixUp(word1, word2) { + return word2.slice(0, 2) + word1.slice(2) + " " + word1.slice(0, 2) + word2.slice(2); +}; +console.log(mixUp("Knowledge", "House")); - - +console.log("---------+---------") //Create a function called fixStart //It should take a single argument, a string, and return a version where all occurences of its first //character have been replaced with '*', except for the character itself. //fixstart('babble'): 'ba**le' //write answer below +function fixStart (leString) { + // establishing 'exclusive' letter + let karac = leString.charAt(0); + return karac + leString.slice(1).replace(new RegExp(karac, 'g'), '*'); +} +console.log(fixStart("JumpingJahasfatsJeeWillikers")); +// i had to look up the RegExp object - - +console.log("---------+---------") //Create a function called verbing. It should take a single argument, a string. //If it's length is at least 3, it should add 'ing' to its end, unless it already ends in 'ing', //in which case it should add 'ly' instead. If the string length is less than 3, From 5eae400e0ffe5d9fed37be99aab2fa18a9b775ba Mon Sep 17 00:00:00 2001 From: "J. J. YOUNG" <41083436+himslf@users.noreply.github.com> Date: Mon, 20 Sep 2021 22:20:26 -0400 Subject: [PATCH 2/2] Final Edit w. tests/results Group Members: Anthony T. & Jenny M. --- string.js | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/string.js b/string.js index 1f86563..c6843d9 100644 --- a/string.js +++ b/string.js @@ -1,4 +1,4 @@ -//DrEvil +// #1 DrEvil //create a function called DrEvil. It should take a single argument, an amount //and return ' dollars', except it will add '(pinky)' at the end if //the amount is 1 million. For example: @@ -19,7 +19,7 @@ DrEvil(1000000); // 1000000 dollars! (pinky) console.log("---------+---------") -//Create a function called mixUp +// #2 Create a function called mixUp //It should take in two stings, and return the concatenation of the two strings(separated by a space) //slicing out and swapping the first 2 characters of each. You can assume that the strings are at least 2 characters long. //For example: @@ -35,7 +35,7 @@ console.log(mixUp("Knowledge", "House")); console.log("---------+---------") -//Create a function called fixStart +// #3 Create a function called fixStart //It should take a single argument, a string, and return a version where all occurences of its first //character have been replaced with '*', except for the character itself. //fixstart('babble'): 'ba**le' @@ -52,7 +52,7 @@ console.log(fixStart("JumpingJahasfatsJeeWillikers")); console.log("---------+---------") -//Create a function called verbing. It should take a single argument, a string. +// #4 Create a function called verbing. It should take a single argument, a string. //If it's length is at least 3, it should add 'ing' to its end, unless it already ends in 'ing', //in which case it should add 'ly' instead. If the string length is less than 3, //it should leave it unchanged. For example: @@ -61,14 +61,29 @@ console.log("---------+---------") //verbing('go'): 'go' //write answer below +function verbing(term) { + if (term.length < 3) { + return term + } + + if (term.slice(-3) == 'ing') { + return term + 'ly'; + } else { + return term + 'ing'; + } +} // end of function +console.log(verbing("run")); +console.log(verbing("pontificate")); +console.log(verbing("Yo")); -//Create a function called notBad that takes a single argument, a string +console.log("---------+---------") +// #5 Create a function called notBad that takes a single argument, a string //It should find the first appearance of the substring 'not' and 'bad' //If the 'bad' follows the 'not', then it should replace the whole 'not'...'bad' //substring with 'good' and return the result @@ -78,4 +93,20 @@ console.log("---------+---------") //notBad('This dinner is not that bad!'): 'This dinner is good!' //notBad('This movie is not so bad!'): 'This movie is good!' //notBad('This dinner is bad!'): 'This dinner is bad!' -//write answer below \ No newline at end of file +//write answer below + +function notBad(expressi0n) { + var houseOfNot = expressi0n.indexOf('not'); + var groupOfBad = expressi0n.indexOf('bad'); + if (houseOfNot == -1 || groupOfBad == -1 || groupOfBad < houseOfNot) return expressi0n; + return expressi0n.slice(0, houseOfNot) + 'good' + expressi0n.slice(groupOfBad + 3); +} + +console.log(notBad("Staying up this late is not that bad!")); +console.log(notBad("Waking up at 3:00PM is not so bad!")); +console.log(notBad("Poor indentation is bad!")); +console.log(notBad("Staying up this late not is that bad!")); // hmmmm... +console.log(notBad("Staying up this late ain't that bad!")); // hmmmm... + + +