diff --git a/dom-events.js b/dom-events.js index ba68614..2c850a8 100644 --- a/dom-events.js +++ b/dom-events.js @@ -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) => { @@ -15,18 +15,51 @@ const astrosEl = document.getElementById("astros") // astrosEl.innerHTML = `` // } - // 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() diff --git a/index.html b/index.html index e87ea19..8a21fa8 100644 --- a/index.html +++ b/index.html @@ -4,9 +4,18 @@ impact fellowship - + + Astronauts

oh hey, there

+
+
+
The most recent key pressed is:
+
Your mouse position is:
+
+
Put your input here:
+
Your input is:
+ diff --git a/practice.js b/practice.js index a334bf9..992d20e 100644 --- a/practice.js +++ b/practice.js @@ -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 = "
  • " + temp + "
  • " + final += temp + tempArray[i] = temp + } + tempList.innerHTML = final +}