Assignment 2: JavaScript Syntax, Variables, and Operators

To complete this assignment, open up this document in a text editor and complete the questions in each ".problem" div


Anything you log to the console with console.log() will display in the JavaScript Console in your browser when you load this page. The JavaScript Console is located in the Developer Console. Right click on this page and choose "inspect". In the toolbar that pops up at the right or bottom of your browser, choose the tab for "Console." You will see anything logged to the console here.


Feel free to use resources like the w3 Schools JavaScript reference.

In your own words, define what "statement", "variable", "Operator" and "array" mean in javascript. Make your answers (strings) display in the appropriate p elements by completing the code between the script tags starting on line 65. You can look this up on W3 schools or another resource and paraphrase.

Statement:

Variable:

Operator:

Array:

1. Complete the code between the script tags to create a variable called "x". Assign x the value "hello world." Display the value of x in the element with the id answer1. Log the value of x to the console.

2. Complete the code between the script tags below. Create two variables called "a" and "b" and assign numbers to the value of each. Add the values of a and b using the addition operator and display this value in the element with the id answer2.

3. Complete the code between the script tags below. Display any string you would like to in the div with the id answer3. Do NOT store the value of this string in a variable.

4. Complete the code between the script tags below. Write a single line comment

5. Complete the code between the script tags below. Write a multi-line comment.

6. Complete your code between the script tags below. Create a variable and assign it the value 6. Create another variable and assign it any value you would like. Using assignment operators, change the value of the first variable to the value of both variables multiplied together. Display the new value of the first variable in the div with the id answer6. On the next line log this value to the console.

7. Write two variables that store two strings of any value you'd like. Concatenate these strings and display the concatenated value in the element with the id answer7.

8. Complete the code between the script tags below to display the value output by myFunction() when the button is clicked. Make the button display the string "I've been clicked".

BONUS POINTS (2): Complete your code between the script tags below. Create an Object called "person" with an object literal declaration. Give this object firstName, lastName and age properties and assign these any values you would like. Display the person.firstName in the element with the id bonus. For an extra point, display the "typeof" object person is in the element with the id bonus2.