0

I am trying to create a function that takes in three parameters, creates a variable that assigns all three strings, to one printable string on three lines. I have tried the following:

function generateHaiku(a, b, c) {
  var haiku = 'a\nb\nc';
  return haiku;
}
var example = generateHaiku("hi", "its", "me");
console.log(example);

but instead of returning the haiku, it returns a b c

i want it to return

hi its me (hi on first line, its on second line, me on third line)

what am i doing wrong?

pilchard
  • 12,414
  • 5
  • 11
  • 23

1 Answers1

0

One way to solve this is to make the haiku var a string literal:

function generateHaiku(a,b,c) {
  var haiku = `${a}\n${b}\n${c}`;
  return haiku;
}
var example=generateHaiku("hi","its","me");
console.log(example);
symlink
  • 11,984
  • 7
  • 29
  • 50
  • Thank you , this worked well. I found out the answer that my teacher wanted without using this way that you posted. It goes as following : line1 + "\n" + line2 + "\n" + line3 – omerweiss Jan 16 '21 at 02:07