Skip to content
Sign upLog in
← Back to Community

How to solve this?

Profile icon
rudy35hernandez

I am stumped on this question. I re-read the entire lesson plan and I am still unable to solve this. Any ideas?

function lottoTicket(age) {
const valid = "Thanks for your purchase!"
const invalid = "Purchase denied. Try again when you're older."
if(age > 18) {
return(valid)
}
else {
return(invalid)
}
}

ageAlice = 12

ageBob = 20

// declare a variable to save Alice's lottoTicket autoresponse and another to save Bob's lottoTicket autoresponse

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
AvaROSE3
Profile icon
rudy35hernandez
Comments
hotnewtop
Profile icon
Coder100

Hi! You haven't done anything with the function yet. Does this work?

function lottoTicket(age) { const valid = "Thanks for your purchase!" const invalid = "Purchase denied. Try again when you're older." if(age > 18) { return(valid) } else { return(invalid) } } let ageAlice = 12; let ageBob = 20; // declare a variable to save Alice's lottoTicket autoresponse and another to save Bob's lottoTicket autoresponse let alicelottoTicket = lottoTicket(ageAlice); let boblottoTicket = lottoTicket(ageBob); console.log("Alice's result:", alicelottoTicket); // Alice's result: Purchase denied. Try again when you're older. console.log("Bob's result:", boblottoTicket); // Bob's result: Thanks for your purchase!
Profile icon
EpicGamer007

when you return something, you have to do
return + the variable you want to return, your syntax is wrong.

@SixBeeps
's answer is correct as well.

Sorry for pinging you if you found it annoying...
Profile icon
SixBeeps

@AbhayBhat
Nah, the syntax is fine
image

Profile icon
EpicGamer007

@SixBeeps
, oh ok, im just a js noob >_<

Profile icon
Coder100

yeah, although return is like return value, the value can also be an expression, and (variable) is an expression. This is also why typeof "hi" and typeof("hi") works as well.

@AbhayBhat

Profile icon
SixBeeps

It's just asking you to create two variables, like on Lines 12 and 14 where it does ageAlice = 12 and ageBob = 20. Create two new ones, and store the value of lottoTicket(person) into each one, respective of the person.

Profile icon
rudy35hernandez

@SixBeeps
So I removed ageAlice = 12 altogether to try to solve one at a time since i can't seem to get both. I added "lottoTicket('Bob') under the ageBob = 20, and "I'm still getting purchase denied. Try again when you're older."
I also tried "console.log(lottoTicket('Bob'));" and I still got the purchase was denied message.