So basically I want to return the string, with a message.
This is what I have so far, why am I getting undefined for the name back I have a series of test that run, and it's supposed to return a empty strong for the first test.
export const twoFer = (name) => {
let saying = "One for" + name + "," + "One for me"
let greeting = saying
if (name === '') {
let greeting = "One for you, One for me"
} else {
let greeting = "One for" + name + ",One for me"
}
return greeting;
};
I thought it would be useful to provide the tests as well so..
import { twoFer } from './two-fer'
describe('twoFer()', () => {
test('no name given', () => {
expect(twoFer()).toEqual("One for you, one for me.")
})
xtest('a name given', () => {
expect(twoFer("Alice")).toEqual("One for Alice, one for me.")
})
xtest('another name given', () => {
expect(twoFer("Bob")).toEqual("One for Bob, one for me.")
})
})
EDIT Final Solution:
export const twoFer = (name = null) => {
if (!name) {
return "One for you, one for me."
} else {
return "One for " + name + "," + " one for me."
}
};
Aucun commentaire:
Enregistrer un commentaire