From 0a658f0720d767e114c66f9ce25061d154c02263 Mon Sep 17 00:00:00 2001 From: Rahat Hossan Date: Tue, 2 Jan 2018 13:52:48 -0500 Subject: [PATCH 1/3] Solved --- practice.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/practice.js b/practice.js index a334bf9..813db25 100644 --- a/practice.js +++ b/practice.js @@ -3,30 +3,58 @@ 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)) From c5ef9d374e99211ab2bef2a950fbd30329886b0d Mon Sep 17 00:00:00 2001 From: rohitmusti Date: Wed, 3 Jan 2018 10:35:05 -0500 Subject: [PATCH 2/3] Some work from earlier this morning - weirdly having trouble with the on click stuff but I understand how to do it --- dom-events.js | 35 ++++++++++++++++++++--------------- index.html | 2 ++ practice.js | 22 ++++++++++++++++++---- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/dom-events.js b/dom-events.js index ba68614..7b32e89 100644 --- a/dom-events.js +++ b/dom-events.js @@ -1,21 +1,26 @@ const greetingEl = document.getElementById("greeting") const astrosEl = document.getElementById("astros") -// window.onload = () => { -// greetingEl.innerText = "oh, hey there!" -// renderAstros() -// } -// -// renderAstros = () => { -// const astros = peopleInSpace["people"] -// let peopleEls = astros.map((a) => { -// let name = a["name"] -// return `
  • ${name}
  • ` -// }) -// astrosEl.innerHTML = `` -// } - - // create a function that alerts "these are all the astronauts!" when the title element is clicked. +window.onload = () => { + greetingEl.innerText = "oh, hey there!" + renderAstros() +} + +renderAstros = () => { + const astros = peopleInSpace["people"] + let peopleEls = astros.map((a) => { + let name = a["name"] + return `
  • ${name}
  • ` + }) + astrosEl.innerHTML = `` +} + +// 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. diff --git a/index.html b/index.html index e87ea19..3befbec 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,9 @@ impact fellowship + Astronauts

    oh hey, there

    +
    diff --git a/practice.js b/practice.js index 813db25..992d20e 100644 --- a/practice.js +++ b/practice.js @@ -11,11 +11,11 @@ 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)) @@ -24,7 +24,7 @@ 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 @@ -50,7 +50,7 @@ const wheresJoe = (data) => { for(i = 0; i < data.number; i++) { //console.log(data.people[i].name) if(data.people[i].name.includes("Joe")) { - + return "in space!" } } @@ -60,3 +60,17 @@ 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 +} From 049a892221ee6a5fea76ef4ff079fe483c7c543c Mon Sep 17 00:00:00 2001 From: rohitmusti Date: Thu, 11 Jan 2018 14:43:19 -0500 Subject: [PATCH 3/3] started creating the js stuff --- dom-events.js | 62 +++++++++++++++++++++++++++++++++++++-------------- index.html | 9 +++++++- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/dom-events.js b/dom-events.js index 7b32e89..2c850a8 100644 --- a/dom-events.js +++ b/dom-events.js @@ -1,19 +1,19 @@ -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() +// } -window.onload = () => { - greetingEl.innerText = "oh, hey there!" - renderAstros() -} - -renderAstros = () => { - const astros = peopleInSpace["people"] - let peopleEls = astros.map((a) => { - let name = a["name"] - return `
  • ${name}
  • ` - }) - astrosEl.innerHTML = `
      ${peopleEls.join("")}
    ` -} +// renderAstros = () => { +// const astros = peopleInSpace["people"] +// let peopleEls = astros.map((a) => { +// let name = a["name"] +// return `
  • ${name}
  • ` +// }) +// astrosEl.innerHTML = `
      ${peopleEls.join("")}
    ` +// } // create a function that alerts "these are all the astronauts!" when the title element is clicked. @@ -24,14 +24,42 @@ title.onclick = () => { // 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 3befbec..8a21fa8 100644 --- a/index.html +++ b/index.html @@ -4,11 +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:
    +