Last active
January 18, 2022 11:46
-
-
Save iancover/05f52831810bd9564890b41e8173152a to your computer and use it in GitHub Desktop.
Thinkful exercises: JS functions using strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shouter(whatToShout) { | |
return whatToShout.toUpperCase () + '!!!' | |
} | |
function testShouter() { | |
var whatToShout = 'as you can hear i am whispering'; | |
var expected = 'AS YOU CAN HEAR I AM WHISPERING!!!'; | |
if (shouter(whatToShout) === expected) { | |
console.log('SUCCESS: `shouter` is working'); | |
} | |
else { | |
console.log('FAILURE: `shouter` is not working'); | |
} | |
} | |
testShouter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function textNormalizer(text) { | |
var text = "let's GO SURFING NOW everyone is learning how" | |
return text.toLowerCase() | |
} | |
function testTextNormalizer() { | |
var text = " let's GO SURFING NOW everyone is learning how "; | |
var expected = "let's go surfing now everyone is learning how"; | |
if (textNormalizer(text) === expected) { | |
console.log('SUCCESS: `textNormalizer` is working'); | |
} | |
else { | |
console.log('FAILURE: `textNormalizer` is not working'); | |
} | |
} | |
testTextNormalizer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wisePerson(wiseType, whatToSay) { | |
return 'A wise ' + wiseType + ' once said: "' + whatToSay + '".'; | |
} | |
function testWisePerson() { | |
var wiseType = 'goat'; | |
var whatToSay = 'Hello World'; | |
var expected = 'A wise ' + wiseType + ' once said: "' + | |
whatToSay + '".'; | |
var actual = wisePerson(wiseType, whatToSay); | |
if (expected === actual) { | |
console.log('SUCCESS: `wisePerson` is working'); | |
} | |
else { | |
console.log('FAILURE: `wisePerson` is not working'); | |
} | |
} | |
testWisePerson(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't understand why on the last one the solution had the ".trim()" method, but Im guessing all it does is take the spaces between the " ".