-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpractice.js
More file actions
66 lines (53 loc) · 1.94 KB
/
practice.js
File metadata and controls
66 lines (53 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
console.log(peopleInSpace)
// const numberOfAstrosInSpace = (data) => {
// //return the number of astronauts in space right now, using the data
// }
// console.log("number of people in space: ", numberOfAstrosInSpace(peopleInSpace))
const astroNames = (data) => {
let people = data.people
let nameArray = people.map((person) => {
return person.name}
)
return nameArray
// return an array containing the name strings of the astronauts in space
}
console.log("names of people in space: ", astroNames(peopleInSpace))
// const allInSameCraft = (data) => {
// // return a boolean that specifies whether all astronauts are in the same space craft
// }
// console.log("same craft? ", allInSameCraft(peopleInSpace))
//
//
// const successfulResponse = (data) => {
// // return a boolean that specifies whether the response from the Open Notify API was successful
// }
// console.log("successful response? ", successfulResponse(peopleInSpace))
//
//
// const wheresJoe = (data) => {
// // return "in space!" if Joe Acaba is in space right now. Otherwise, return "dunno."
// }
// console.log("where's Joe? ", wheresJoe(peopleInSpace))
// BONUS
// Using your astroNames function, dynamically render each of the astronauts' names to the DOM in an unordered list when the page loads.
// const greeting = document.getElementById("greeting")
// console.log(greeting)
//
const list = document.getElementById("astroList")
window.onload = () => {
let nameArray = astroNames(peopleInSpace)
let listItems = nameArray.map((name) => { return "<li>" + name + "</li>"})
domString = listItems.join("")
list.innerHTML = domString
// console.log(listItems)
}
const title = document.getElementsByClassName("title")[0]
title.onclick = () => {
alert("these are all the astronauts!")
}
form = document.getElementsByTagName('form')[0]
textInput = document.getElementById("textInput")
form.onsubmit = (event) => {
event.preventDefault()
console.log(textInput.value)
}