Bingo explainer

Aim of the puzzle: Write a function that takes a number and returns 'bingo' if it’s greater than 4.
Walk through of solution: To complete this puzzle, create a function named card. Inside the parentheses () of the function declaration, add a parameter called num. Inside the code block {} of the function declaration, add an if statement that returns 'bingo' if num > 4. Then, outside the function declaration, use console.log() to print card(5).

Don’t forget to type out the whole function declaration:

  • The function keyword
  • The name of the function, card
  • The parameter, num, inside the parentheses ()
  • The if and return statements, if (num > 4){ return 'bingo' } inside the code block {}

Javascript Concepts: function, if statement, strings, numbers, parameters

I don’t know if there is an error or what, but the code isn’t executing.

Hey there, post a screenshot of your code, and I can take a look and give you some pointers.

Thanks,
Ben

hello,

I am having difficutly solving this puzzle, please see below of the code and advise what I am missing:

function card(num) {
if (num > 4)
return (‘bingo’)
}
console.log(card(5))

Hey there, post a screenshot of your code, rather than typing it out, and I’ll take a look.

Thanks,
Ben

Hello, I do something wrong but what, please help me to find my mistake(s)
Screenshot_2019-10-16%20Bingo%20%E2%80%93%20Using%20a%20Code%20Editor%20%E2%80%93%20Grasshopper

Hey there,

It looks like the if statement is missing the brackets for a code block {}.

Try changing the function to this:

function card(num) {
    if (num > 4) {
        return 'bingo';
    }
}

Hope this helps! Let me know if you have any questions.
Ben

1 Like

function card(num) {
if (num > 4) {
return (‘bingo’);
}
}
console.log (card(5))

Thank you very much Ben this worked…

I ran through it with your response with someone that was also running into the same error and it got solved.

thank you

function card(num) {
    if (num>4)
        return ('bingo')
    }
console.log(card(5))

My code returns ‘bingo’ but the program still says I’m wrong, what should I do ?
below is the message I get.

Inside the code block {} of the if statement, return 'bingo' . For example: if (num > 4) { return 'bingo' } .

Here’s how I got it to work: I placed a code bracket in front of return and another at the end before console.log

function card(num) {
    if(num > 4) {
        return ('bingo');
    }
}
console.log(card(5));
3 Likes

thanks, I got it to work with the extra brackets, but why are they needed ? the code i entered was still returning ‘bingo’ without them

Hey there, brackets are used to create code blocks, and are a necessary part of telling the computer that certain blocks of code belong together.

For example, a function:

function someFunction() {
   code goes here...
}

Or a for loop:

for (let x of y) {
    code goes here...
}

Or an if statement:

if (thisIsTrue) {
   code goes here...
}

Hope this clarifies things! Let me know if you have any questions.
Ben

this one worked thanks Joel

I just did it but I don’t what it’s not working.

Hi, I need some help with this.
Thanks in advanced.

Hey there,

The return 'bingo' needs to be in the code block {} of the if statement. It doesn’t look like the if statement has a code block.

It should look like this:

function card(num) {
    if (num > 4) {
        return 'bingo';
    }
}

hey would this be correct17%20PM