Skip to content

Instantly share code, notes, and snippets.

@iancover
Last active January 18, 2022 11:46
Show Gist options
  • Save iancover/05f52831810bd9564890b41e8173152a to your computer and use it in GitHub Desktop.
Save iancover/05f52831810bd9564890b41e8173152a to your computer and use it in GitHub Desktop.
Thinkful exercises: JS functions using strings
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();
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();
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();
@iancover
Copy link
Author

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 " ".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment