0

Im really new to JavaScript and I was wondering how would I be able to insert multiple varibles into a string?

var adjective1 = 'amazing';
var adjective2 = 'fun';
var adjective3 = 'entertaining';



var madLib = "The Intro to JavaScript course is (adjective1). James and Julia are so (adjective2). I cannot wait to work through the rest of this (adjective3) content!";
console.log(madLib);
Evelyn
  • 186
  • 1
  • 4
  • 25

1 Answers1

2

You can use Template literals (Template strings)

Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them. They were called "template strings" in prior editions of the ES2015 specification.

var adjective1 = 'amazing';
var adjective2 = 'fun';
var adjective3 = 'entertaining';

var madLib = `The Intro to JavaScript course is ${adjective1}. James and Julia are so ${adjective2}. I cannot wait to work through the rest of this ${adjective3} content!`;
console.log(madLib);
Mamun
  • 66,969
  • 9
  • 47
  • 59