Przeglądaj źródła

Small Refactor for Readability

Nick Satinover 7 lat temu
rodzic
commit
d640a824bc
4 zmienionych plików z 81 dodań i 29 usunięć
  1. 3
    0
      .idea/misc.xml
  2. 4
    1
      GoldenGateBridge.js
  3. 74
    0
      Practice.html
  4. 0
    28
      Practice.js

+ 3
- 0
.idea/misc.xml Wyświetl plik

@@ -3,4 +3,7 @@
3 3
   <component name="JavaScriptSettings">
4 4
     <option name="languageLevel" value="ES6" />
5 5
   </component>
6
+  <component name="ProjectPlainTextFileTypeManager">
7
+    <file url="file://$PROJECT_DIR$/Practice.js" />
8
+  </component>
6 9
 </project>

+ 4
- 1
GoldenGateBridge.js Wyświetl plik

@@ -21,7 +21,10 @@ function movieFunction(movieArr) {
21 21
     var match = "Golden Gate Bridge";
22 22
     for(var i = 0; i < movieArr.length; i++) {
23 23
         if (movieArr[i][10] === match)
24
-            listGateMovies += movieArr[i][8] + ' ' + movieArr[i][9] + ' ' + movieArr[i][12] + '<br>';
24
+            listGateMovies +=
25
+                movieArr[i][8] + ' ' +
26
+                movieArr[i][9] + ' ' +
27
+                movieArr[i][12] + '<br>';
25 28
     }
26 29
     document.getElementById("result").innerHTML = listGateMovies;
27 30
 

+ 74
- 0
Practice.html Wyświetl plik

@@ -0,0 +1,74 @@
1
+<!DOCTYPE html>
2
+<html lang="en">
3
+<head>
4
+    <meta charset="UTF-8">
5
+    <link href="./css/style.css" type="text/css" rel="stylesheet">
6
+    <title>Import Local JSON Data | Zipcode Wilmington</title>
7
+</head>
8
+<body>
9
+<header class="main-header group">
10
+    <div class="title"><h1>Zipcode Wilmington<br>Javascript Lab - Fall 2015</h1></div>
11
+    <div class="lesson-link"><img src="./images/logos/js_logo.png" alt="Javascript"/></div>
12
+    <div class="zip-link"><img src="./images/logos/zip_logo.jpg" alt="Zipcode Wilmington"/></div>
13
+</header>
14
+
15
+<article>
16
+    <h1>Instructions</h1>
17
+    <p>Us the <code>XMLHttpRequest()</code> to receive the remote json feed from the following website<br>
18
+        https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD
19
+    </p>
20
+
21
+    <p>The json feed list movies made in San Francisco</p>
22
+
23
+    <p>Write the following info for each movie to the webpage:
24
+    <ul>
25
+        <li>movie title</li>
26
+        <li>release year</li>
27
+        <li>production company</li>
28
+    </ul>
29
+    </p>
30
+
31
+    <p>Only list movies that were made at the Golden Gate Bridge</p>
32
+
33
+    <p>Use <code>document.getElementById('result').innerHTML += <i>your_output</i>;</code> to write the movie's info to the page.</p>
34
+    <p>Append <code>"&ltbr&gt"</code> to output code to create a new line</p>
35
+</article>
36
+
37
+<section>
38
+    <h1>Movie Information</h1>
39
+    <div id="result"></div>
40
+</section>
41
+<script>
42
+    var xmlhttp = new XMLHttpRequest();
43
+    var url = "https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD";
44
+    var data;
45
+    var listGateMovies = "";
46
+
47
+    xmlhttp.open("GET", url, true);
48
+
49
+    xmlhttp.onreadystatechange = function () {
50
+        if (xmlhttp.readyState == 4 && xmlhttp.status === 200){
51
+            data = JSON.parse(this.responseText);
52
+            var movieArr = data.data;
53
+            movieFunction(movieArr);
54
+        }
55
+    }
56
+
57
+    xmlhttp.send();
58
+
59
+    function movieFunction(movieArr) {
60
+        for(var i = 0; i < movieArr.length; i++) {
61
+            if (movieArr[i][10] === "Golden Gate Bridge") {
62
+                listGateMovies +=
63
+                    movieArr[i][8] + ' ' +
64
+                    movieArr[i][9] + ' ' +
65
+                    movieArr[i][12] + '<br>';
66
+
67
+            }
68
+        }
69
+        document.getElementById("result").innerText = listGateMovies;
70
+    }
71
+
72
+</script>
73
+</body>
74
+</html>

+ 0
- 28
Practice.js Wyświetl plik

@@ -1,28 +0,0 @@
1
-var url = "https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD";
2
-var xmlhttp = new XMLHttpRequest();
3
-var data;
4
-var listGateMovies = "";
5
-
6
-xmlhttp.open("GET", url, true);
7
-
8
-xmlhttp.onreadystatechange = function() {
9
-    if (this.readyState == 4 && this.status == 200) {
10
-        console.log(xmlhttp.response);
11
-        data = JSON.parse(this.responseText);
12
-        var movieArr = data.data;
13
-        movieFunction(movieArr);
14
-    }
15
-};
16
-
17
-xmlhttp.send();
18
-
19
-
20
-function movieFunction(movieArr) {
21
-    var match = "Golden Gate Bridge";
22
-    for(var i = 0; i < movieArr.length; i++) {
23
-        if (movieArr[i][10] === match)
24
-        listGateMovies += movieArr[i][8] + ' ' + movieArr[i][9] + ' ' + movieArr[i][12] + '<br>';
25
-    }
26
-    document.getElementById("result").innerHTML = listGateMovies;
27
-
28
-}