Exercise 2.2

Hello $name! author(s): Cameron King

HTML

<script src="https://ckxng.github.io/cub-scout-coding/lib/easy.js"></script>
<p>
  As you've seen a few times, strings can be added together with the plus (+)
  operator to make longer strings. This can even be used to add variables to
  strings. But, when you are putting variables into strings, there is an even
  easier way.
</p>

<p>
  The fancy name for it is "interpolation". But that's a little hard to say. So
  we're going to call it "substituion". String substitution uses the backtick
  (`) instead of double quotes (") to wrap strings. Then, variables can be
  included using the dollar sign ($) like this <tt>`Hello ${name}!`</tt>. That's
  pretty different, but you'll get the hang of it.
</p>

<p>
  (TIP! The backtick (`) is next to the one (1) key on most keyboards.)
</p>

<p>
  Here is an example that does it both ways. Give it a try below. Can you write
  a sentence that uses substitution?
</p>

JavaScript

name = "world";

say("Hello "+name+"! Goodbye "+name+"!");

say(`Hello ${name}! Goodbye ${name}!`);