From e40eedf28f09dbe44b8c2036012aba63b962e770 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 20 Sep 2021 22:45:19 -0400 Subject: [PATCH 1/2] Anthony's commit --- string.js | 85 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/string.js b/string.js index 07d52da..530d0ab 100644 --- a/string.js +++ b/string.js @@ -5,36 +5,47 @@ // DrEvil(10): 10 dollars // DrEvil(1000000): 1000000 dollars (pinky) // answer below: - - - - - - +function DrEvil(amount) { + if (amount === 1000000) { + console.log(`${amount} dollars pinky`) + } + else { + console.log(`${amount} dollars`) + } +} + +DrEvil(1231); +DrEvil(1000000); //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. +//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: //mixUp('mix', 'pod'): 'pox mid' //mixUp('dog', 'dinner'): 'dig donner' //write answer below +function mixUp(string1, string2) { + let holder1 = string1.slice(1); + let holder2 = string2.slice(1); + let holder3 = string2[0] + holder1 + ' ' + string1[0] + holder2; + console.log(holder3); +} - - - - +mixUp("sup", "bye"); //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(string1) { + let holder1 = string1.slice(1) + let holder2 = string1[0] + holder1.replace(/b/g, '*'); + console.log(holder2); +} +fixStart("babble"); //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', @@ -44,13 +55,21 @@ //verbing('swimming'): 'swimmingly' //verbing('go'): 'go' //write answer below - - - - - - - +function verbing(string1) { + if (string1.includes("ing")) { + console.log(string1 + "ly"); + } + else if (string1.length >= 3) { + console.log(string1 + "ing"); + } + else { + console.log(string1); + } +} + +verbing("swim"); +verbing("swimming"); +verbing("Hi"); //Create a function called notBad that takes a single argument, a string //It should find the first appearance of the substring 'not' and 'bad' @@ -62,4 +81,20 @@ //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(string1) { + if(!string1.includes("not" || "bad")){ + console.log(string1); + return + } + else{ + let holder1 = string1.indexOf("not"); + let holder2 = string1.indexOf("bad"); + if (holder1 < holder2) { + console.log(string1.slice(0, holder1) + "good"); + } + } +} +notBad('This dinner is not that bad!'); +notBad('This movie is not so bad!'); +notBad('This dinner is bad!'); \ No newline at end of file From 0fe9799318687906fa310bf34df5a5e9e860ad0f Mon Sep 17 00:00:00 2001 From: anthony Date: Sun, 26 Sep 2021 14:23:01 -0400 Subject: [PATCH 2/2] first commit --- index.html | 13 ++++++++ string.js | 89 ++++++++++++++++++++++++++---------------------------- 2 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..2649f49 --- /dev/null +++ b/index.html @@ -0,0 +1,13 @@ + + + + + + + Document + + + + + + \ No newline at end of file diff --git a/string.js b/string.js index 530d0ab..b9fcc57 100644 --- a/string.js +++ b/string.js @@ -1,17 +1,16 @@ //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 +//and return ' dollars', except it will add '(pinky)' at the end if //the amount is 1 million. For example: // DrEvil(10): 10 dollars // DrEvil(1000000): 1000000 dollars (pinky) // answer below: function DrEvil(amount) { - if (amount === 1000000) { - console.log(`${amount} dollars pinky`) - } - else { - console.log(`${amount} dollars`) - } + if (amount === 1000000) { + console.log(`${amount} dollars pinky`); + } else { + console.log(`${amount} dollars`); + } } DrEvil(1231); @@ -20,81 +19,77 @@ DrEvil(1000000); //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 +//slicing out and swapping the first 2 characters of each. You can assume //that the strings are at least 2 characters long. //For example: //mixUp('mix', 'pod'): 'pox mid' //mixUp('dog', 'dinner'): 'dig donner' -//write answer below +//write answer below function mixUp(string1, string2) { - let holder1 = string1.slice(1); - let holder2 = string2.slice(1); - let holder3 = string2[0] + holder1 + ' ' + string1[0] + holder2; - console.log(holder3); + let holder1 = string1.slice(1); + let holder2 = string2.slice(1); + let holder3 = string2[0] + holder1 + ' ' + string1[0] + holder2; + console.log(holder3); } -mixUp("sup", "bye"); +mixUp('sup', 'bye'); //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. +//character have been replaced with '*', except for the character itself. //fixstart('babble'): 'ba**le' //write answer below function fixStart(string1) { - let holder1 = string1.slice(1) - let holder2 = string1[0] + holder1.replace(/b/g, '*'); - console.log(holder2); + let holder1 = string1.slice(1); + let holder2 = string1[0] + holder1.replace(/b/g, '*'); + console.log(holder2); } -fixStart("babble"); +fixStart('babble'); //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: +//in which case it should add 'ly' instead. If the string length is less than 3, +//it should leave it unchanged. For example: //verbing('swim'): 'swimming' //verbing('swimming'): 'swimmingly' //verbing('go'): 'go' //write answer below function verbing(string1) { - if (string1.includes("ing")) { - console.log(string1 + "ly"); - } - else if (string1.length >= 3) { - console.log(string1 + "ing"); - } - else { - console.log(string1); - } + if (string1.includes('ing')) { + console.log(string1 + 'ly'); + } else if (string1.length >= 3) { + console.log(string1 + 'ing'); + } else { + console.log(string1); + } } -verbing("swim"); -verbing("swimming"); -verbing("Hi"); +verbing('swim'); +verbing('swimming'); +verbing('Go'); //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 -//If it doesn't find 'not' and 'bad' in the right sequence (or at all), just +//If it doesn't find 'not' and 'bad' in the right sequence (or at all), just //return the original sentence //For example //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 +//write answer below function notBad(string1) { - if(!string1.includes("not" || "bad")){ - console.log(string1); - return - } - else{ - let holder1 = string1.indexOf("not"); - let holder2 = string1.indexOf("bad"); - if (holder1 < holder2) { - console.log(string1.slice(0, holder1) + "good"); - } - } + if (!string1.includes('not' || 'bad')) { + console.log(string1); + } else { + let holder1 = string1.indexOf('not'); + let holder2 = string1.indexOf('bad'); + if (holder1 < holder2) { + console.log(string1.slice(0, holder1) + 'good'); + } + } } notBad('This dinner is not that bad!'); notBad('This movie is not so bad!'); -notBad('This dinner is bad!'); \ No newline at end of file +notBad('This dinner is bad!');