JavaScript logical operators

Hi , my code output a error and I can’t understand what am I doing wrong :frowning:
//the exercise:

Using the logical operators you just learned, write an expression that represents the following statement:
“I would like an ice cream with strawberry and either chocolate or stracciatella, or an ice cream of any flavour but caramel.”

Declare a variable named iceCream and assign it the logical expression.

//my code:

var chocolate;
var strawberry;
var stracciatella;
var caramel;
var iceCream = strawberry && chocolate || strawberry && stracciatella || chocolate && stracciatella && !caramel;

//output this error:
Output

Code is incorrect

‘any flavour but caramel’ can be written as not caramel

take a look at your last option:
" chocolate && stracciatella && !caramel "

and compare it to what it requested:
" an ice cream of any flavour but caramel "

1 Like

tks for the hint should I create a var “anyFlavour”?

I just tried and output a different error… I know somehow its in front of my eyes…but I´m stuck

var chocolate = true;
var strawberry = true;
var stracciatella = true;
var caramel = true;
var anyFlavour = true;
var iceCream = strawberry && chocolate || strawberry && stracciatella || chocolate && stracciatella || anyFlavour && !caramel;

Output

Code is incorrect

Did you consider strawberry and chocolate? //I did…

I think you need to devide this in sections

if I write it as

hint: you can say in which order stuff is evaluated with parenthesis

1 Like

Tks for your help, I tried as a string, but still get an error, a different one though…

var chocolate = true;
var strawberry = true;
var stracciatella = true;
var caramel = true;
var iceCream = “I would like an ice cream with strawberry && chocolate || stracciatella || chocolate && stracciatella || an ice cream of any flavour but && !caramel”;

Output

Code is incorrect

There are three possible combinations of ice cream, so your expression should have two ‘or’ operators

it asks for an expression, not a string
iceCream final value should be a Boolean

1 Like

ufff, I’ve got it, tks for all the help!!!