D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
xiuxiuwang
Full window
Github gist
Leveraging Web Data Class 5 Assignment Xiuxiu Wang
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Leveraging Web Data Class 5 Homework</title> </head> <body> <h1 style="text-align: center;"> Leveraging Web Data Class 5 Homework Xiuxiu Wang</h1> <p>Answer the following questions about JavaScript. These questions may require you to do your own research to determine the best answer.</p> <br> <p>Developer Resources</p> <ul> <li><a href="https://www.google.com" target="_blank">Google</a></li> <li><a href="https://www.stackoverflow.com" target="_blank">Stack Overflow</a></li> <li><a href="https://www.w3schools.com/" target="_blank">W3 Schools</a></li> <li><a href="https://devdocs.io/javascript/" target="_blank">Dev Docs</a></li> </ul> <br> <h2>Basic</h2> <h3>Append your name to the text between the title tags.</h3> <br> <h3>Describe the purpose of JavaScript, how might it relate to web mapping and visualization?</h3> <p>JavaScript is the programming language of HTML and the Web. So JavaScript is the tool to manipulate web pages, perform actions, animate and style the web page visualization through its language. It is JavaScript's responsibility to fulfill the web mapping and visualization.</p> <br> <h2>Variables</h2> <h3>What is a variable? Provide two examples of using a variable.</h3> <p>Variables are used to store information to be referenced and manipulated in a function.They also provide a way of labeling data with a descriptive name, so the function can be easy to understood. <br> For example, y = 2x + 1, in which x is a variable that can be any number, and the other variable y will change its values correpsonding to x. <br> Another example is as below: <br> A = 2; B = 20; C = 200; Define a varibale D equals to the sum of A, B, C. In this case, D is a variable that we used to represent for the sum of values listed before. </p> <br> <h3>Write out how to assign the variable x equal to 10.</h3> <p> x == 10</p> <br> <h2>Operators</h2> <h3>Describe the differences between =, ==, and ===.</h3> <p>Firstly, = means define the variable as something, which is changeable. <br> Secondly, == means that set the variable equal to a fixed value, which cannot be changed. <br> Thirdly, === is used to compare two values, the return value is True or Fales.</p> <br> <h3>What would be the result of "Hello " + 10? Why?</h3> <p>It will return an error since JavaScript cannot add two values with different styles. As for this example, "Hello" is a string type, but 10 is int value, so when print "Hello" +10, it will return an error.</p> <br> <h2>Loops</h2> <h3>What is the purpose of a for loop? Describe in detail the advantages of using the for loop.</h3> <p>In reality, there are a lot of situations that happened duplicated or there is loop relationship inside. Thus, Loop is used to shorten and simplify the writing of coding, but could also achieve the same result. It is a sequence of instructions that is continually repeated until a certain condition is reached. <br> For loop is used to repeat a specific block of code a known number of times. The advantage to a for loop is we know exactly how many times the loop will execute before the loop starts. </p> <br> <h3>Describe the while loop in JavaScript.</h3> <p>The while loop loops through a block of code as long as a specific condition is true. If the condition given is always true, the loop won't stop and will continue execute unless close the window.</p> <br> <h2>If/Else Statements</h2> <h3>What are the three <a href="https://www.w3schools.com/js/js_if_else.asp" target="_blank">conditional statements</a>? Describe how each are used.</h3> <p>The three conditional statements are 'if', 'else if', and 'else'. To be specific, use 'if' to specify a block of code to be excuted, if a specific condition is true. For example, if (n=10){s=n+1}. On the hand, use else to specify a lock of code to be excuted, if the same condition is false. For example, if (n=10){s=n+1}; else {s = 10}. Lastly, use else if statement to specify a new condition if the first condition is false. <br> if (condition1) { block of code to be executed if condition1 is true } <br> else if (condition2) { block of code to be executed if the condition1 is false and condition2 is true } <br> else { block of code to be executed if the condition1 is false and condition2 is false }</p> <br> <h3>What is the difference between using two if statements together compared to using an if statement then an else if statement or else statement?</h3> <p>Using two if statements means it will evaluate the first condition whether it is true, and then to execute the second if condition and untile both conditions are true, the following code can be executed. <br> However, the if and else if or else statement is to first evaluate the first if statement condition. When the first if condition is false, then to execute the else if or the else statement condition. </p> <br> <script type="text/javascript"> // // code goes below this line function myNewFunction(){ var i=1; for (i=1, i <101, i++){ if (i%3 == 0 && i%5 == 0){console.log(“Hello World”);} else if (i % 3 == 0){console.log(“Hello”);} else if (i % 5== 0){console.log(“World”);} else {console.log(i);}; }; return myNewFunction();} var x = myNewFunction(); </script> </body> </html>