Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions dom-events.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const greetingEl = document.getElementById("greeting")
const astrosEl = document.getElementById("astros")

// const greetingEl = document.getElementById("greeting")
// const astrosEl = document.getElementById("astros")
//
// window.onload = () => {
// greetingEl.innerText = "oh, hey there!"
// renderAstros()
// renderAstros()
// }
//

// renderAstros = () => {
// const astros = peopleInSpace["people"]
// let peopleEls = astros.map((a) => {
Expand All @@ -15,18 +15,51 @@ const astrosEl = document.getElementById("astros")
// astrosEl.innerHTML = `<ul>${peopleEls.join("")}</ul>`
// }

// create a function that alerts "these are all the astronauts!" when the title element is clicked.
// create a function that alerts "these are all the astronauts!" when the title element is clicked.

var title = document.getElementsByClassName('title')[0]
title.onclick = () => {
alert('these are all the astronauts')
}

// log to the console the client's x coordinate of their mouse as they move it around the window.

function getPos(e) {
x = e.clientX
// console.log(x)
document.getElementById("mouseposition").innerHTML=x
}


// make an element that displays the most recent key pressed in the DOM

function uniCharCode(event) {
var char = event.which || event.keyCode;
var final = String.fromCharCode(char)// console.log(char)
document.getElementById("mostrecent").innerHTML = final;
}

// create a text input element. When a user clicks on the text field to input, log the input element to console.

// when a user clicks away from the input, log ("bye") to the console.
function log() {
var text = document.getElementById('inputtext').value
console.log(text)
document.getElementById("userinput").innerHTML=text
event.preventDefault();
}

// when a user clicks away from the input, log ("bye") to the console.
// wrap the input element with a form element.

// when the form is submitted, render the client's inputted text to the DOM


function clickaway() {
console.log("bye")
event.preventDefault();
}


// NO EXTRA JAVSCRIPT NEEDED HERE


// HINT: look into event.preventDefault()
11 changes: 10 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
<meta charset="utf-8">
<title>impact fellowship</title>
</head>
<body>
<body onmouseover="getPos(event)" onkeypress="uniCharCode(event)">
<span class="title">Astronauts</span>
<p>oh hey, there</p>
<div id="astroList"></div>
<br/>
<div> The most recent key pressed is: <a id="mostrecent"></a></div>
<div> Your mouse position is: <a id="mouseposition"></a></div>
<br/>
<form><div>Put your input here: <input id="inputtext"></input><button onClick="log()" onblur="clickaway()">SUBMIT</button></div></form>
<div>Your input is: <a id="userinput" style= "color: red" ></a></div>
<script src="spaceData.js"></script>
<script src="practice.js"></script>
<script src="dom-events.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,74 @@ console.log(peopleInSpace)

const numberOfAstrosInSpace = (data) => {
//return the number of astronauts in space right now, using the data
return data.number
}
console.log("number of people in space: ", numberOfAstrosInSpace(peopleInSpace))


const astroNames = (data) => {
// return an array containing the name strings of the astronauts in space
let astroname = []

for(i = 0; i < data.number; i++) {
astroname[i] = data.people[i].name
}

return astroname
}
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
var val1 = data.people[0].craft

for(i = 0; i < data.number; i++) {
if(data.people[i].craft =! val1) {
return false
}
}
return true
}
console.log("same craft? ", allInSameCraft(peopleInSpace))


const successfulResponse = (data) => {
// return a boolean that specifies whether the response from the Open Notify API was successful
if(data.message == "success"){
return true
}
return false
}
console.log("successful response? ", successfulResponse(peopleInSpace))


const wheresJoe = (data) => {
// return "in space!" if Joe Acaba is in space right now. Otherwise, return "dunno."
for(i = 0; i < data.number; i++) {
//console.log(data.people[i].name)
if(data.people[i].name.includes("Joe")) {

return "in space!"
}
}
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 tempList = document.getElementById("astroList")
window.onload = () => {

tempArray = astroNames(peopleInSpace)
final = ""

for(i = 0; i < tempArray.length; i++) {
temp = tempArray[i]
temp = "<li>" + temp + "</li>"
final += temp
tempArray[i] = temp
}
tempList.innerHTML = final
}