How to consolidate these two console logs into one)

Hello! I was trying to make this one console.log() entry for a really long time and still can’t figure it out. Would love some help.

Screenshot_2

Since you are using ES6 syntax (template literal) you can write is a single, multiline string…

 > userName = ``
 > userQuestion = 'Why is the sky blue'
 > let a = `${userQuestion}?
${userName === `` ? `Great question!` : `${userName}, great question!`}`
 > console.log(a)
   Why is the sky blue?
   Great question!
 > userName = `Wee Gillis`
 > a = ${userName ? `${userName}, g` : `G`}reat question!`
 > console.log(a)
   Why is the sky blue?
   Wee Gillis, great question!
 > 

Tested and varified. Thank you, sir! That alone was a massive lesson in syntax.

1 Like

Expressions within expressions within expressions is completely legitimate in string literals. I’m going to edit that code one more time, while I can. See if you can spot the difference.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.