Site Title

Homework

Arrays are like containers! They group multiple elements under one variable. You can see this by observing the code and the output. (run it)

%%html

<html>

<body>
  <h2>Output</h2>
  <div id="output"></div>

  <script>
    document.getElementById("output").innerText = ""; // Clear output
    (() => {

        let numbers = [1, 2, 3, 4];
        console.log(numbers);
        document.getElementById("output").innerText += numbers;


    })();
  </script>
</body>
</html>

Output

You can see that you only had to type one variable instead of multiple to get the group of numbers. Try it out yourself to get the concept

Part A of the homework (Graded for completion)

%%html

<html>

<body>
  <h2>Output 2</h2>
  <div id="outputpls"></div>

  <script>
    document.getElementById("outputpls").innerText = ""; // Clear output
    (() => {

        let titleofthings = ["THING 1", "THING 2", " and THING 3", ];
        const sentence = "I like to: " + titleofthings;
        console.log(sentence);
        document.getElementById("outputpls").innerText += sentence;


    })();
  </script>
</body>
</html>

Output 2

Once you have ran the code, see how your list is generated without you having to type each individual word into the DOM. This concept applies to all other situations where you would want to reference your list.

Part B (Graded for completion)

%%html

<html>

<body>
  <h2>Output</h2>
  <div id="output3"></div>

  <script>
    document.getElementById("output3").innerText = ""; // Clear output
    (() => {

      
      let NAME = [LIST];
      // Replace the blanks, that look like this _____, below! HINT: the line above
      const smallParagraph = "After school, I like to " + _____ + ". This is because " + _____ + " is really fun to me. I think you should try " + _____ + "."; 
      console.log(smallParagraph);
      document.getElementById("output3").innerText += smallParagraph;


    })();
  </script>
</body>
</html>

Output

If you did that correctly, you’ll realize that you would’ve spent a LOT more time on that if you decided to type out your list every time it occured in those sentences instead of just using an array. When people use arrays, they have the goal of efficiency, and also organization. Arrays can help code from getting too lengthy, especially if the list if quite long and is referenced quite a lot.

Part C (Graded on whether it worked or not)

Try it out yourself!

%%html

<html>

<body>
  <h2>Output</h2>
  <div id="output4"></div>

  <script>
    document.getElementById("output4").innerText = ""; // Clear output
    (() => {

        


    })();
  </script>
</body>
</html>

Output

Submit here

https://docs.google.com/forms/d/e/1FAIpQLSfqHrQwvgNYvxxUxMD5mIfSgfZGkiDu6uPV0I_GMG8wqSQzpw/viewform?usp=header