Media

Assignment 2 - LINES ON PAPER

Overall worth: 10%

Background

You have been bad! The teacher caught you putting gum under your seat. It is time you learn some JavaScript. On PAPER with pen or pencil write the following
(NO COMPUTER PRINT OUT) - each part worth half a mark:

Task 1

NOTE: Answer each question separately (not all one big answer)

1. JS Write FIVE variables for different types of candies - use camelCase where applicable. Put the number of candies you have for each type as a the variable value. Make sure you declare the variable with the correct const or let. For instance, let gobStop = 10;

2. JS Concatenate the variable values into a long string with the format of: "I have ___ GobStops and "... so all your candies and values are in one sentence with their number where I have the ___.

3. JS Make variables called most and mostType and set most equal to 0 and mostType equal to null. Then write a conditional for each candy type that tests to see if there are more candies of that type than the value of most. If there are more candies then set most to the amount of candies and set mostType to the string name of the candy variable. After all five conditionals, console.log mostType and most.

4. JS Make an array called gums and put 5 flavours as strings into the array.

5. JS Declare a variable called flavours and set it equal to "My flavours are: ". In a loop, loop through the array and concatenate the flavour at each index and a comma then space to the flavours variable. If the loop is on the last index (use the array's length property), then do not concatenate the comma and the space. After the loop, console.log the result.

6. JS Use push, pop, shift and unshift methods of the array to do the following: Remove a flavour of gum from the end of the array (and store it in a variable). Add a new flavour of gum to the end of the array. Take the flavour of gum that you removed from the end and add it to the beginning of the array.

7. JS Make a function called remove and have it collect two parameters called flavour1 and flavour2. Have the function randomly choose from the parameters and then remove the selected parameter value from the array of gum flavors if it happens to be there (indexOf and splice).

8. JS Make an object literal called sodaPop with name, cost and rating properties. Supply appropriate values. After making the object, add a new property called color using the dot syntax and give color a value. Change the cost value using the array access operator [].

9. JS Make an empty array called drinks and push the sodaPop object onto the array. Console.log the price property using the drinks array and two array access operators [][].

10. JS Write three different formats of an Arrow Function.

Task 2

OMG. That was a lot of hand writing. And then, someone tattled on you and said you complained! But you did not. Now, the teacher now wants you to do more lines. These ones are worth 1 mark each!

11. DOM Write the window event for when the HTML tags have loaded and imagine that the body tag has an id of page. You do not have to write the body tag. Inside the event function set the backgroundColor style of the body to black if the time is in the PM and white if the time is in the AM.

12. DOM Write the JavaScript code to create a nav tag with content of one anchor tag (a) to your favourite site. Append the nav tag to the top of the body.

13. OOP Write the code to make a class called Speak that will log to the console one of three random types of sentences. The first is an insult. The second is a compliment. And the third is a complaint. Make a Speak object.

14. OOP Write the code for a method called repeat() that would be added inside constructor of your Speak class that would repeat the chosen sentence in the console.

15. OOP Write the alternative code for a method called repeat() where repeat is defined outside the constructor. What two different things could you do to your class code so that the method knows what was said?

Requirements

Hand pages (stapled would be nice) to Teacher at the start of class on the due date (remember, always come to class even if you are not done). Or if a remote class submit scans (or pictures if you must) of the papers on Slate by the due date.

Breakdown

Task 1 - 1/2 MARK Per Question
Task 2 - 1 MARK Per Question