Leveraging Web Data Class 5 Homework

Answer the following questions about JavaScript. These questions may require you to do your own research to determine the best answer.


Developer Resources


Basic

Jordan McCutcheon.


Describe the purpose of JavaScript, how might it relate to web mapping and visualization?

JavaScript is a programming language that helps with the performance, manipulation and user interaction of web pages. JavaScript can be its own file or embedded in a HTML file. JavaScript can be used in in web mapping and visualization for processes such as creating buttons and changing the color of the maps text. This will help enhance the visual appeal of your web map.(Class 5, Slide 10)


Variables

What is a variable? Provide two examples of using a variable.

A Variable is used in JavaScript to hold values. One example is when you want to give value to a string such as a person’s name. You can use the following variable Var Name = “Jordan McCutcheon”; You can also create a variable with simple math. Var Y = 3 + 5 +7+9; You can also use a variable to combine two string values together. ( source, https://www.w3schools.com/js/js_variables.asp)


Write out how to assign the variable x equal to 10.

var x = 10;


Operators

Describe the differences between =, ==, and ===.

The = value assigns a value. (X =5) then x is 5. The == values checks if a value is equal to another value. (x==5) is only true of x = 5. The === is the same as == but it also must share the same type. If value 1 is a string for it to be === to value 2, value 2 must also be a string and have the same value as value 1. (source https://www.w3schools.com/jsref/jsref_operators.asp )


What would be the result of "Hello " + 10? Why?

Due to concatenation, the result would be Hello 10. Concatenation will add an operator with a string. (source, slide 31)


Loops

What is the purpose of a for loop? Describe in detail the advantages of using the for loop.

Loops are useful when you want to run the same script repeatedly with a different value. A for loops is used when you want to repeat up to a certain value or a certain number of times, saving the user time. When creating a for loop, make sure you have an endpoint, or the code will run until it crashes your system. (source, slide 25, 26, 27, and, 28)


Describe the while loop in JavaScript.

In JavaScript a while loop goes through a block of code until a specified condition is met. Then the script will stop, and the user will get their results. (source https://www.w3schools.com/js/js_loop_while.asp)


If/Else Statements

What are the three conditional statements? Describe how each are used.

The if statement is used to show which code should be run when met with a specific condition. The else statement is used to show which code should be run when a specific condition is false. The else if statement is used to create a new if statement when the first one is false. (source, https://www.w3schools.com/js/js_if_else.asp)


What is the difference between using two if statements together compared to using an if statement then an else if statement or else statement?

When using two if statements if the outcome of the first one meets the condition of the second statement it will make the second statement true. When using an else if statement only the if or the else if can be true not both. When using an else statement only the if or else can be true not both. (source, https://stackoverflow.com/questions/4636191/is-there-any-difference-between-using-multiple-if-statements-and-else-if-stateme)