ICE CREAM Quiz

hi,

will like to ask what is wrong with my code. It doesn’t work on codecademy quiz.

The question

Define an order() function that announces your ice cream order.

It should take two arguments: the number of scoops and the flavor. It should return the order in this format: "Lemme get [number] scoops of [flavor]!" It should use “scoop” when number is 1 and “scoops” for anything greater.

For example:

// Returns "Lemme get 1 scoop of vanilla!"order(1, 'vanilla');// Returns "Lemme get 3 scoops of chocolate!"order(3, 'chocolate');

My answer

function order (number, ‘flavor’) {

if (number === 1){

return “Lemme get " + number + “scoop of " + flavor”!”

}else (number > 1) {

return "Lemme get " + number + "scoops of " + flavour"!"

}

}

order(2, ‘vanilla’)

Thank you in advance!

Hey there,

My answer

function order (number, 'flavor') {
  if (number === 1) {
    return "Lemme get " + number + "scoop of " + flavor"!"
  } else (number > 1) {
    return "Lemme get " + number + "scoops of " + flavour"!"
  }
}

order(2, 'vanilla')

A few things stand out here.

  • On the first line, for the function parameters, you’re sometimes using quotes and sometimes not. Is there a particular reason?

  • You’re also using flavor, but then sometimes switch to flavour. In code, these will be interpreted as two different things.

  • Speaking of which, check the color or “r” in flavor and “ur” in flavour (return statements). Why do you reckon this happens? Anything possibly missing?

  • In an if-else statement, else cannot take a condition. However, else if can.

  • Do you need to log the result?

1 Like

Hey object8666811689,
In your first line:

function order (number, ‘flavor’) {

I’m pretty sure you should define the function parameter flavor without quotes.

And on your return lines, in the end you should use another + for the “!”, like this:

return "Lemme get " + number + "scoops of " + flavor + "!"

Also, as mentioned on the reply above me, flavor and flavour will be interpreted by the computer as two different things.

Good luck!

1 Like

Thank you so much.

I have revised the code to this, it still does not work. Appreciate your further inputs.

Thanks in advance!

function orders (number, flavor) {

if (number === 1){

return "Lemme get " + number + "scoop of " + flavor + “!”

}else if (number > 1) {

return "Lemme get " + number + "scoops of " + flavor + “!”

}

}

order(2, vanilla)

1 Like

This is already better, well done!

Still a few things to take a look at:

function orders(number, flavor) {        #orders?

  if (number === 1) {

    return "Lemme get " + number + "scoop of " + flavor + "!"     # ;

  } else if (number > 1) {

    return "Lemme get " + number + "scoops of " + flavor + "!"  # ;

  }

}

order(2, vanilla)      #order? vanilla?
  • If you call order on an orders function, it won’t work :wink:
  • I’d advise you to put semi-colons ( ; ) after your return statements, to clearly mark the line end
  • Function parameters (number, flavor) do not take quotes. You did well there. However, function arguments should take quotes if the argument is a string. And since we’re returning strings, it makes sense to put vanilla between double quotes.

Try these to see if it works then :slight_smile:

2 Likes

:joy: :sob: :sneezing_face: finally! It works now :sob:

Thank you so much!

function orders (number, flavor) {

if (number === 1){

return "Lemme get " + number + " scoop of " + flavor + “!”;

}else if (number > 1) {

return "Lemme get " + number + " scoops of " + flavor + “!”;

}

}

console.log(orders(1, “vanilla”))

1 Like

Thank you too! :sneezing_face:

1 Like