Przeglądaj źródła

Finish for statement lesson

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang 5 lat temu
rodzic
commit
6b00ad3495
2 zmienionych plików z 19 dodań i 1 usunięć
  1. 12 0
      notes.js
  2. 7 1
      todo.js

+ 12 - 0
notes.js

@@ -10,6 +10,18 @@ const notes = ['Note 1', 'Note 2', 'Note 3']
 
 notes[2] = 'This is the new note 3'
 
+notes.forEach(function (item, index) {
+    console.log(index)
+    console.log(item)
+})
+
 console.log(notes.length)
 console.log(notes)
 
+for (let count = 0; count <= 2; count++) {
+    console.log(count)
+}
+
+for (let count = 0; count < notes.length; count++) {
+    console.log(notes[count])
+}

+ 7 - 1
todo.js

@@ -8,4 +8,10 @@ todo.push('Email Paulo')
 todo.shift()
 
 console.log(`You have ${todo.length} todos.`)
-console.log(todo)
+// todo.forEach(function (item, index) {
+//     console.log(`${index + 1}. ${item}`)
+// })
+
+for (let count = 0; count < todo.length; count ++) {
+     console.log(`${count + 1}. ${todo[count]}`)
+}