the code i was given was :
const coffees = [
"light colombian roast", "hawaiian dark roast", "guatemalan blend medium roast",
"madagascar espresso roast", "jamaican dark blue", "jamaican medium roast",
"salvador robusto light", "bali espresso roast"
]
for () {
}
the exercise goes as follows:
Depending on the roast, you prepare the coffee differently. If it is a light roast, you drink it black. If it is a medium roast, you put cream in it. If it is a dark roast, you put cream and sugar in it.
Your job is to iterate the coffees array and output the following sentences for each coffee. Replace the xxx placeholder with the full name of the coffee.
For light roast, output “I’ll have the xxx and drink it black”
For medium roast, output “I’ll have the xxx and add cream only”
For dark OR espresso roast, output "I’ll have the xxx and add cream and sugar
In this exercise, you will use a for…of loop and conditional logic with if/else blocks again. You will also use a new tool to find a smaller string value within a bigger string value. You will also use the logical OR operator || which is similar to the logical AND operator && you have used in previous exercises.
I am new to javascript and I just cant figure out how to get this code to pass
Welcome, jonathon.
The red next to the line numbers are indicating a syntax error. Line 10
contains the syntax error, as well as Line 12
.
Also, no element in coffees
is === 'light'
. Some elements do contain 'light'
…
For future posts, please post either code, or, best case scenario, a link to your project.
Hope this helps
also note that if you separate a list of things using the ||
OR operator, the list will resolve to just one of the items in the list
Hello Sky,
I just changed the descrition and added the code and added the exercise description.
and what’s your code instead?
It is so much easier for us to help you if you copy and past the text of your code into a forum post. Please use the </>
button or place backticks ```
on new lines before and after your code. You could also share the link to your repl.
Unexpected token, expected }
means that you forgot a }
. You did not close const coffees = {....
Im sorry I am very new to this
this is the link to the repl
This link is very helpful, thank you.
I was wrong about the }
. There are a few things going on here.
- You can’t put line breaks like that into a
console.log()
. You’ll want to use \n
.
- Your
'
s are a little strange. Are they smart quotes or something like that?
-
coffeeRoast
isn’t defined, which is going to cause you a problem.
- You are pushing into
coffeeRoast
in a loop based upon coffeeRoast
? That will cause problems.
- You probably want to use lower case first letter for
darkRoast
.
- You probably mean
black
, cream
, and sugar + cream
.
Big picture, what would you like this code to do? It seems like you are missing some variables and some big picture pieces here?
1 Like