0

How can I rewrite the console.log rules using the following variables.

let blocksGehaald = ["Iron Man", "Pitch Perfect", "One of a Kind"]
let cleGehaald = true
let favoriteBlock = 0
console.log(`Mijn favoriete block is Iron Man!`)
console.log(`Ik heb 3 building blocks gehaald!`)

I tried to make a new variable

let a = Iron man
console.log('Mijn favoriete block is ${a} !')

I don't get an error but it's not the right answer according to my teacher, I have to use something else

shrys
  • 5,860
  • 2
  • 21
  • 36
Merve
  • 1
  • 1

2 Answers2

2

You need to use back tick if you are using template literals. Also array is 0 indexed base. So to retrieve the Iron Man from array you have to pass zero like blocksGehaald[favoriteBlock] assuming 0 is stored in variable `favoriteBlock``

let blocksGehaald = ["Iron Man", "Pitch Perfect", "One of a Kind"]
let cleGehaald = true
let favoriteBlock = 0

console.log(`Mijn favoriete block is ${blocksGehaald[favoriteBlock]}!`)
brk
  • 48,835
  • 10
  • 56
  • 78
0

Try this:

let a = "Iron man"
console.log(`Mijn favoriete block is ${a} !`)

In Javascript, single quotes (') and double quotes (") are the same.

Ticks (``) on the other hand are different in the sense that they also allow for the use of ${}.

goodvibration
  • 5,980
  • 4
  • 28
  • 61