Vinicius Sena Posted December 21, 2022 at 09:41 PM Report Share #629103 Posted December 21, 2022 at 09:41 PM Boa Noite, Estou nos primeiros passo de programação e resolvendo alguns exercícios on-line estou com problemas com operadores de lógica no seguinte exercício: 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. var chocolate; var strawberry; var stracciatella; var caramel; o exercício já declara as variáveis acima, então procedo com o desenvolvimento: var chocolate = true; var strawberry = true; var stracciatella = true; var caramel = false; var iceCream = (strawberry || chocolate)(strawberry || stracciatella)!caramel; porém me retorna o erro: >>>>Code is incorrect syntax error Unexpected token '!' Além da sintaxe, também estou errando na lógica ? Link to comment Share on other sites More sharing options...
Solution Zex Posted December 21, 2022 at 11:49 PM Solution Report Share #629107 Posted December 21, 2022 at 11:49 PM A expressão é como o enunciado. Basta substituir "and" por "&&", "or" por "||", colocar uns parentesis e pouco mais. 1 Report Link to comment Share on other sites More sharing options...
Vinicius Sena Posted December 22, 2022 at 11:53 AM Author Report Share #629116 Posted December 22, 2022 at 11:53 AM correto novamente... Link to comment Share on other sites More sharing options...
jsWizard Posted February 22, 2023 at 12:58 PM Report Share #630210 Posted February 22, 2023 at 12:58 PM "I would like an ice cream with strawberry and either chocolate or stracciatella, or an ice cream of any flavour but caramel." var willIHaveAnIceCream = (strawberry && (chocolate || stracciatella)) || !caramel O resultado não é o ice cream (sabores).. mas simplemente se vais comer o ice cream ou não. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now