Strings 4

Test your skills: Strings

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
    <title>Strings: Task 4</title>
    <style>
      p {
        color: purple;
        margin: 0.5em 0;
      }

      * {
        box-sizing: border-box;
      }
    </style>
    <link rel="stylesheet" href="../styles.css" />
  </head>

  <body>

    <section class="preview">



    </section>

  </body>
  <script>
    let theorem = 'Pythagorean theorem';

    let a = 5;
    let b = 8;
		
    let myString = 'Using *, we can work out that that if the two shortest sides of a right-angled triangle have lengths of * and *, the length of the hypotenuse is *.';
		myString = `Using ${theorem}, we can work out that that if the two shortest sides of a right-angled triangle have lengths of ${a} and ${b}, the length of the hypotenuse is ${Math.sqrt(a**2 + b**2) }.`;
    console.log(myString);
    // Don't edit the code below here!

    const section = document.querySelector('section');

    let para1 = document.createElement('p');
    para1.textContent = myString;
    section.appendChild(para1);
  </script>

</html