Skip to content

Instantly share code, notes, and snippets.

@desinas
Last active December 12, 2023 20:17
Show Gist options
  • Save desinas/b492dfb90b15acf9de92cf1546d5b27b to your computer and use it in GitHub Desktop.
Save desinas/b492dfb90b15acf9de92cf1546d5b27b to your computer and use it in GitHub Desktop.
JavaScript intro to functions Mocha tested by Flatiron School, learn.co
// describe('shout(string)', function() {
// it('receives one argument and returns it in all caps', function() {
// expect(shout('hello')).toEqual('HELLO')
// })
// })
function shout (aWord) {
return aWord.toUpperCase( );
}
// describe('whisper(string)', function() {
// it('receives one argument and returns it in all lowercase', function() {
// expect(whisper('HELLO')).toEqual('hello')
// })
// })
function whisper (aWord) {
return aWord.toLowerCase( );
}
// describe('logShout(string)', function() {
// it('calls console.log() its one argument in all caps', function() {
// const spy = expect.spyOn(console, 'log').andCallThrough()
// logShout('hello')
// expect(spy).toHaveBeenCalledWith('HELLO')
// console.log.restore()
// })
// })
function logShout (aWord) {
console.log(aWord.toUpperCase( ));
}
// describe('logWhisper(string)', function() {
// it('calls console.log() its one argument in all lowercase', function() {
// const spy = expect.spyOn(console, 'log').andCallThrough()
// logWhisper('HELLO')
// expect(spy).toHaveBeenCalledWith('hello')
// console.log.restore()
// })
// })
function logWhisper (aWord) {
console.log(aWord.toLowerCase( ));
}
// describe('sayHiToGrandma(string)', function() {
// it('returns "I can\'t hear you!" if `string` is lowercase', function() {
// expect(sayHiToGrandma('hello')).toEqual("I can't hear you!")
// })
// it('returns "YES INDEED!" if `string` is uppercase', function() {
// expect(sayHiToGrandma('HELLO')).toEqual("YES INDEED!")
// })
// it('returns "I love you, too." if `string` is "I love you, Grandma."`', function() {
// expect(sayHiToGrandma("I love you, Grandma.")).toEqual("I love you, too.")
// })
// })
function sayHiToGrandma (aWord) {
var cantUnswer = "I can't hear you!";
var yesUnswer = "YES INDEED!";
var lovUnswer = "I love you, too.";
if (aWord.toLowerCase(aWord) === aWord) {
return cantUnswer;
}
else if (aWord.toUpperCase(aWord) === aWord) {
return yesUnswer;
}
else if ("I love you, Grandma." === aWord) {
return lovUnswer
}
}
@Lord-Gitonga
Copy link

THANK YOU.

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