Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions 04week/hiOrderFunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Person = {

//Use a for...in loop and if statement to console.log the value associated
//with the key birthDate if the birth year is an odd number.
//find diff way to find odd values

for (const property in Person){
if(property.birthDate % 3 === 0){
Expand Down
5 changes: 5 additions & 0 deletions 06week/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Created an array of people to choose from of eligible players, with different attributes for each of them.
Created different classes to hold the attributes and move them from array to array, and display them in the DOM. Created a listPeopleChoices function to create new players and map through the array of people. Creates a button that allows you to make a player that when clicked moves the object to the listOfPlayers array. Once listOfPlayers is created they are given two button options for the red or blue team which when clicked will move them to the selected array.
step 1: Array of People
step 2: ARRAY OF PLAYERS
STEP 3: array of red or blue team
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the requirements was a test plan write up, or some tests. I dont see either of those.

29 changes: 29 additions & 0 deletions 06week/dodgeball.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Dodge Ball</title>
</head>
<body>
<div>
<h4>List Of People</h4>
<ul id="people"></ul>
</div>
<button onclick="listPeopleChoices()">List People</button>
<div>
<h4>Dodge Ball Players</h4>
<ul id="players"></ul>
</div>
<div>
<h4>Blue Team</h4>
<ul id="blue"></ul>
</div>
<div>
<h4>Red Team</h4>
<ul id="red"></ul>
</div>
<script src='dodgeball.js'></script>
</body>
</html>
202 changes: 202 additions & 0 deletions 06week/dodgeball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
const arrOfPeople = [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like that you put comments through out. But the indentation could use a little more work. It is not strictly necessary for the code to run, but it would make it easier to read and follow along

{
id: 2,
name: "Charles Young",
age: 55,
skillSet: "welding",
placeBorn: "Omaha, Nebraska"
},
{
id: 3,
name: "Judy Twilight",
age: 35,
skillSet: "fishing",
placeBorn: "Louisville, Kentucky"
},
{
id: 4,
name: "Cynthia Doolittle",
age: 20,
skillSet: "tic tac toe",
placeBorn: "Pawnee, Texas"
},
{
id: 5,
name: "John Willouby",
age: 28,
skillSet: "pipe fitting",
placeBorn: "New York, New York"
},
{
id: 6,
name: "Stan Honest",
age: 20,
skillSet: "boom-a-rang throwing",
placeBorn: "Perth, Australia"
},
{
id: 7,
name: "Mia Watu",
age: 17,
skillSet: "acrobatics",
placeBorn: "Los Angeles, California"
},
{
id: 8,
name: "Walter Cole",
age: 32,
skillSet: "jump rope",
placeBorn: "New Orleans, Louisiana"
},
]
//take list of people and create new player instances
//there should NOT be two teammate classes only one not blueTeammate and redTeammate
//teammate class which represents a player once they get selected for a team
//attribute of teammate class should be teamname all teammates have an attribute called team name
//if you blue your attribute will say blue if youre red your attribute will say red
const listOfPlayers = []
const blueTeam = []
const redTeam = []

class player {
constructor(id, name, age, skillSet, placeBorn){
this.id = id;
this.name = name;
this.age = age;
this.skillSet = skillSet;
this.placeBorn = placeBorn;

//listPeopleChoices
}
}

//the parent class is player, the child is teammate
class Teammate extends player {
constructor(id, name, age, skillSet, placeBorn, teamName){
super(id, name, age, skillSet, placeBorn);//super calls player constructor
this.teamName = teamName;
/*if your a blue teammate you attribute will say blue,
if you a red teammamte your attribute will say red*/
}
}
//teammate class should extend the player class
//Ex: truck extends vehicle
//every teammate has the same attributes of player plus one more
//which is which team theyre on
const listPeopleChoices = () => {
const listElement = document.getElementById('people')
arrOfPeople.map(person => {
//loops through arrOfPeople array
//creates list item tag
const li = document.createElement("li")
//creates button element
const button = document.createElement("button")
//text in button reads make player
button.innerHTML = "Make Player"
//when the button is clicked...
button.addEventListener('click', function() {makePlayer(person.id)} )
li.appendChild(button)
li.appendChild(document.createTextNode(person.name + " - " + person.skillSet))
listElement.append(li)
})
}

const makePlayer = (id) => {
let playerElement = arrOfPeople.find(function(player){
//find players with "id" in arrOfPeople
return player.id == id;

});
//goes through index of arrOfPeople with id
let index = arrOfPeople.indexOf(playerElement);
//takes out selected value
arrOfPeople.splice(index, 1);
//removes 1 item from arrayOfPeople array
let newPlayer = new player (playerElement.id, playerElement.name, playerElement.age, playerElement.skillSet, playerElement.placeBorn);
//creates a new player object
//adds newPlayer object to listOfPlayers array
listOfPlayers.push(newPlayer);
//calls PlayerDisplay function from below
//PlayerDisplay();
console.log(newPlayer)
PlayerDisplay();
};

const makeBluePlayer = (player) => {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have been the place to create a Teammate instance and have it store the team color.

blueTeam.push(player);
//push value into blueTeam array

let bluePlayer = listOfPlayers.indexOf(player);
//index of player in listOfPlayers array
//the indexOf listOfPlayers array is assigned to bluePlayer
//takes out one item, bluePlayer value from listOfPlayers array
listOfPlayers.splice(bluePlayer, 1)
document.getElementById("blue").innerHTML = "";
PlayerDisplay();
const blueEl = document.getElementById('blue')
//loops (map) through blueTeam array
blueTeam.map(players => {
const li = document.createElement("li");
li.appendChild(document.createTextNode(`${players.name} - ${players.id}`))
blueEl.append(li);
})
};

const makeRedPlayer = (player) => {
//push value into redTeam array
redTeam.push(player);
//indexOf player in listOfPlayers array is assigned to redPlayer
const redPlayer = listOfPlayers.indexOf(player);
//take out 1 item, redPlayer of listOfPlayers array
listOfPlayers.splice(redPlayer, 1)
document.getElementById("red").innerHTML = "";
PlayerDisplay();
const redEl = document.getElementById('red');


//loops (map) through redTeam array
redTeam.map(players => {
const li = document.createElement("li");
li.appendChild(document.createTextNode(`${players.name} - ${players.id}`))
redEl.append(li);
})
};

const PlayerDisplay = () => {
const listElement = document.getElementById('players')
listElement.innerHTML = "";
//finds the id player and assigns it to list element
listOfPlayers.map(person => {
//loops through listOfPlayers array
//creates "li" tag
const li = document.createElement("li")
//li.appendChild(document.createTextNode(`${person.name} - ${person.skillSet}`))
listElement.append(li)
document.getElementById("people").innerHTML = "";
listPeopleChoices();
//creates button
const button1 = document.createElement("button")
//creates button
const button2 = document.createElement("button")
//text in "button1" reads blue team
button1.innerHTML = "Blue Team"
// text in "button2" reads read team
button2.innerHTML = "Red Team"
//when button1 is clicked calls makeBluePlayer function
button1.addEventListener('click', function() {makeBluePlayer(person)} )
li.appendChild(button1)
//li.appendChild(document.createTextNode(person.id + " - " + person.name))
listElement.append(li)
//when button2 is clicked calls makeRedPlayer function
button2.addEventListener('click', function() {makeRedPlayer(person)} )
li.appendChild(button2)
li.appendChild(document.createTextNode(person.name + " - " + person.age))
listElement.append(li)
})
};
//var judy = new player (3, "Judy Twilight", 35, "fishing", "Louisville, Kentucky")
//console.log(judy);

/*if your a blue teammate you attribute will say blue,
if you a red teammamte your attribute will say red*/
61 changes: 37 additions & 24 deletions 06week/sorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@ const strNums = ["1","4","1","5","9","2","6","5","3","5","8","9","7","9","3","2"
// Given 1000 digits of PI as strings, return an array of the digits as numbers
//use map function
const stringsToNumbs = (numbers) => {
numbers.map
const toNum = parseInt(strNums[numbers]);
}
console.log(stringsToNumbs);
console.log(stringsToNumbs());
// With the same numbers, find the sum of the even values
//use reduce and filter hi order functions
const sumEvens = (numbers) => {
let total = 0;
if (strNums[i] % 2 === 0){
total += strNums[i];
}

};
let strToInt = numbers.map(x => parseInt(x))
let evenArray = strToInt.filter(x => x % 2 === 0);
let total = evenArray.reduce((t, n) => t + n)
return total
}

console.log(sumEvens);
console.log(sumEvens(strNums));

// Find the index of the first value when added to it's index = 512 (#ATX!!)
const atxIdx = (numbers) => {
let total = 0;
if(total + strNums[i] < 512){
total += strNums[i];
}
else if (total + strNums[i] === 512){
return true;
}
};

console.log(`index: ${atxIdx}, value: ${nums[atxIdx]}`);
const num = (numbers) => {
let strToInt = numbers.map(x => parseInt(x))
//return strToInt
strToInt.forEach(function(item, index, array){
//console.log(item, index)
if(item + index === 512){
console.log("item: " + item, "index: " + index)
console.log(item + index)
}else{
return false;
}
})
}
console.log(num(strNums));

const weather = [
{ id: 5743823523151872,
Expand Down Expand Up @@ -96,14 +98,25 @@ const weather = [
visibility: 11.14056410562316,
predictability: 71
},
],
];

//using a higher order function, create an array of the unique 'weather_state_name' values of the weather array.
//Your function should return the following array ['Light Cloud', 'Heavy Cloud', 'Showers']
const weatherStates = weather.forEach(function(element, index){
console.log(element.weather_state_name);
let weatherArray = [];
const weatherStates = weather.forEach(function(element){
if(weatherArray.includes(element.weather_state_name)){
//do nothing
//access the weather_state_name using the new array??
}else {
weatherArray.push(element.weather_state_name)
//return weatherArray
}
//console.log(weatherArray)
//console.log(element.weather_state_name);
//ran in repl.it without console.log////
})
console.log(weatherStates)
//put in new array and if it already exist in new array
console.log(weatherArray)

//find the id of the object in weather that has a min_temp of 15.915

Expand Down
3 changes: 3 additions & 0 deletions 07week/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5502
}
11 changes: 11 additions & 0 deletions 07week/addressAPI.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

<script src="addressAPI.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions 07week/addressAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const getPosts = () => {
return fetch(`https://randomuser.me/api/`)
.then(res => res.json())
.then(res => console.log(res))

}

console.log(getPosts());