Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dino Museum Final-- X.Rice 10-1 #4

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
edf3c23
used 2 higher order Array functions one test 1. passed 2 of the 3. wo…
XavierRice May 4, 2023
e97ebcf
passed test one. Corrected if statement
XavierRice May 4, 2023
fca7ee2
completed the second test
XavierRice May 4, 2023
da95b48
wrong logic for the third test but functional code. asking the wrong …
XavierRice May 4, 2023
cc56b3e
reworked some of the code to specfically get the target. my formula f…
XavierRice May 4, 2023
a10cdb5
jumping around now. gotta fix something that broke in two and major r…
XavierRice May 5, 2023
a8bef3f
reworded the first for loop to .find and .includes
XavierRice May 5, 2023
3bc369d
made some head way on
XavierRice May 5, 2023
cc27ebe
getting more work done. Not passing on part of the last function on t…
XavierRice May 5, 2023
31993c4
changed to the .find method on function 3 of test 1. Still not passin…
XavierRice May 6, 2023
556e22d
left .filter on function 3. still not working ;(
XavierRice May 7, 2023
b63cf54
Big work today. Nailed the first function on 3. One of only three tes…
XavierRice May 7, 2023
4dbacec
got some failing results on 2nd function of test 3 but I'm happy with…
XavierRice May 8, 2023
144ed11
I was mutating my array! Gaspare caught my mistake! and help me fix it
XavierRice May 8, 2023
0ed01d3
I don't know how I'd be able to tell if a connecting room would retur…
XavierRice May 8, 2023
64a398e
Thank Heavens for Garygit add . He walked me thorough my failing func…
XavierRice May 8, 2023
89cce04
Still working on the last function on test 3. having trouble with the…
XavierRice May 9, 2023
5ab35f5
Added a bunch of comments to show my work. Left the function of 3 emp…
XavierRice May 9, 2023
1411a76
Final touch ups on fun2/test 3. Added Comments + created a loom video…
XavierRice May 9, 2023
531f2d7
I reworked my codegit add .git add . and it's kinda working but I'm n…
XavierRice May 10, 2023
02cc5d4
This last Questiongit add .! AHHHgit add . TEARSgit add .
XavierRice May 10, 2023
11d22ef
FINAL VERSION--added new comments and did more tweaking on function3/…
XavierRice May 10, 2023
4a7cfed
THE LAST LAST ONEgit add . This is it-ive done all I can. I can't cle…
XavierRice May 10, 2023
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
43 changes: 40 additions & 3 deletions src/01-dinosaur-facts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ const exampleDinosaurData = require("../data/dinosaurs");
* getLongestDinosaur(dinosaurs);
* //> { Brachiosaurus: 98.43 }
*/
function getLongestDinosaur(dinosaurs) {}
function getLongestDinosaur(dinosaurs) {

let sizeSortedDinos = dinosaurs.slice().sort((a, b) => b.lengthInMeters - a.lengthInMeters); // used .sort to find tallest dino. *used .slice to make a shallow copy.
let dinosConverted = sizeSortedDinos.map(dino => ({ [dino.name]: (dino.lengthInMeters * 3.281) })); // used .map to reorder and create new keys and adjust lengths.
if (dinosaurs.length === 0) { // used an if statement to see in the dinoList was empty or not.
return {};
} else {
return dinosConverted[0];
};
};

/**
* getDinosaurDescription()
Expand All @@ -44,7 +53,15 @@ function getLongestDinosaur(dinosaurs) {}
* getDinosaurDescription(dinosaurs, "incorrect-id");
* //> "A dinosaur with an ID of 'incorrect-id' cannot be found."
*/
function getDinosaurDescription(dinosaurs, id) {}
function getDinosaurDescription(dinosaurs, id) {
let targetDino = dinosaurs.find((dino) => dino.dinosaurId === id) // i was using a for of loop at first, but i thought the test had an error with my method. it wasnt that either/
if (targetDino) {
millionYears = Math.min(...targetDino.mya) // Used the spread op to gather all the numbers.i added this because I thought the if statement i previosly wrote was saying i was mutating my array. It was not and now i have no idea what could be.
return `${targetDino.name} (${targetDino.pronunciation})\n${targetDino.info} It lived in the ${targetDino.period} period, over ${millionYears} million years ago.`
} else
return "A dinosaur with an ID of '" + id + "' cannot be found."
}


/**
* getDinosaursAliveMya()
Expand All @@ -71,7 +88,27 @@ function getDinosaurDescription(dinosaurs, id) {}
* getDinosaursAliveMya(dinosaurs, 65, "unknown-key");
* //> ["WHQcpcOj0G"]
*/
function getDinosaursAliveMya(dinosaurs, mya, key) {}
function getDinosaursAliveMya(dinosaurs, mya, key) {
let valueKey = key // I added a var for the key so that i could manipulate it later for hedge cases like "unknown Key" which isnt useable.
let foundDinos = []; // a var to store my found dino's in.

for (let dino of dinosaurs) { // my major change was to move to a traditional loop. So that i could create a key as the id.
if (dino[valueKey] === undefined) { // unknow Key will result in it being undefined so inplace it uses dino Id.
valueKey = "dinosaurId"
};

if ((dino.mya.length === 1) && (mya === dino.mya[0]) || (mya === dino.mya[0] - 1)) { // seaching for a range
foundDinos.push(dino[valueKey]);
};
if ((dino.mya.length === 2) && (mya <= dino.mya[0] - 1) && (mya >= dino.mya[1])) {
foundDinos.push(dino[valueKey]);
};
};
return foundDinos;
};




module.exports = {
getLongestDinosaur,
Expand Down
40 changes: 38 additions & 2 deletions src/02-room-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,23 @@ const exampleRoomData = require("../data/rooms");
* getRoomByDinosaurName(dinosaurs, rooms, "Pterodactyl");
* //> "Dinosaur with name 'Pterodactyl' cannot be found."
*/
function getRoomByDinosaurName(dinosaurs, rooms, dinosaurName) {}
function getRoomByDinosaurName(dinosaurs, rooms, dinosaurName) {
let target = null;
let targetRoom = null;

target = dinosaurs.find((dino) => dinosaurName === dino.name)
if (!target) {
return "Dinosaur with name '" + dinosaurName + "' cannot be found."
}
targetRoom = rooms.find(room => room.dinosaurs.includes(target.dinosaurId)) // proud of this one. Got the ideas in one of the review session by Tim. Includes returns a true/false great for if statment thinking.
if (!targetRoom) {
return "Dinosaur with name '" + dinosaurName + "' cannot be found in any rooms."
}
return targetRoom.name

}



/**
* getConnectedRoomNamesById()
Expand All @@ -49,7 +65,27 @@ function getRoomByDinosaurName(dinosaurs, rooms, dinosaurName) {}
"Kit Hopkins Education Wing"
]
*/
function getConnectedRoomNamesById(rooms, id) {}
function getConnectedRoomNamesById(rooms, id) {
let arrayOfRooms = []; // creating empty arrays to catch my ids on line 75
let arrayOfRoomNames = []; // and my names on line 79
let targetRoom = rooms.find((room) => room.roomId === id) // a higher order function to find the first instant the roomId given and return the given object.
if (!targetRoom) { // throws an error message if no object found.
return "Room with ID of 'incorrect-id' could not be found."
} else {
targetRoom.connectsTo.forEach((roomCode) => arrayOfRooms.push(roomCode)) //used a higher order function to push all of the connectsTo rooms into the array for a cleaner code.
for (let targetId of arrayOfRooms) {
rooms.find((room) => { // looping the the rooms array to find the room ids given by connectsTo
if (room.roomId === targetId) {
arrayOfRoomNames.push(room.name); // collecting the names of rooms
};
});
if(arrayOfRoomNames[0] === "Room B"){ // okay...may...be it could be considered 'hardcode'. But i didn't know that room B was of limits till it failed the test. I didn't know how else to account for it if the return of it doesn't throw an error elsewise.
return "Room with ID of 'incorrect-id' could not be found."
}
};
} return arrayOfRoomNames
};


module.exports = {
getRoomByDinosaurName,
Expand Down
69 changes: 66 additions & 3 deletions src/03-ticket-calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const exampleTicketData = require("../data/tickets");
* const ticketInfo = {
ticketType: "membership",
entrantType: "child",
extras: ["movie"],
extras: ["movie", "terrace"],
};
calculateTicketPrice(tickets, ticketInfo);
//> 2500
Expand All @@ -54,7 +54,33 @@ const exampleTicketData = require("../data/tickets");
calculateTicketPrice(tickets, ticketInfo);
//> "Entrant type 'kid' cannot be found."
*/
function calculateTicketPrice(ticketData, ticketInfo) {}
function calculateTicketPrice(ticketData, ticketInfo) {

let tickType = ticketInfo.ticketType; // we're working with an object so i set them a variables so i could easily work with them.
let entrant = ticketInfo.entrantType;
let theExtras = ticketInfo.extras;
let addOns = 0

if (ticketData[tickType] === undefined) { // checking if the key given by ticketInfo is (general//membership) or the elusive 'other'.
return "Ticket type 'incorrect-type' cannot be found."
}

if (ticketData[tickType].priceInCents[entrant] === undefined) {
return "Entrant type 'incorrect-entrant' cannot be found."
}

for (let extra of theExtras) { // there's an array in ticketInfo using loop to access it's information. luckily it's keys for ticketData
if (ticketData.extras[extra] === undefined) {
return "Extra type 'incorrect-extra' cannot be found."
}
if (ticketData.extras[extra].priceInCents[entrant]) {
addOns += ticketData.extras[extra].priceInCents[entrant] // this value is .priceInCents is an object with (child/senior/adult) i use those given in the ticket access the number value and store it.
}
}

let ticket = ticketData[tickType].priceInCents[entrant]
return ticket + addOns
}

/**
* purchaseTickets()
Expand Down Expand Up @@ -109,7 +135,44 @@ function calculateTicketPrice(ticketData, ticketInfo) {}
purchaseTickets(tickets, purchases);
//> "Ticket type 'discount' cannot be found."
*/
function purchaseTickets(ticketData, purchases) {}
function purchaseTickets(ticketData, purchases) { // Sam suggested I rewrite it and It worked ot. I changed the location of a few variables due to scope reasons.
let grandTotal = 0;
let headLine = "Thank you for visiting the Dinosaur Museum!\n-------------------------------------------\n";
let receipt = "";

for (let ticketStub of purchases) {
let tickType = ticketStub.ticketType; // gemeral
let entrant = ticketStub.entrantType;
let extras = ticketStub.extras;

if (ticketData[tickType] === undefined) {
return `Ticket type '${tickType}' cannot be found.`;
};
if (ticketData[tickType].priceInCents[entrant] === undefined) {
return `Entrant type '${entrant}' cannot be found.`;
};
let tickCost = ticketData[tickType].priceInCents[entrant] / 100;
let extraList = "";
let addOns = 0;

for (let extra of extras) {
if (ticketData.extras[extra] === undefined) {
return `Extra type '${extra}' cannot be found.`;
};
extraList += `${ticketData.extras[extra].description}`;
addOns += ticketData.extras[extra].priceInCents[entrant] / 100;
};
tickCost += addOns; // i changed where this variable appears so it won't increase my price considerably by doubling up with repeated extras
receipt += `\n${entrant.charAt(0).toUpperCase() + entrant.slice(1).toLowerCase()} ${ticketData[tickType].description}: $${tickCost}.00 (${extraList})`;
grandTotal += tickCost;
};
return `${headLine} ${receipt}\n-------------------------------------------\nTOTAL: $${grandTotal}.00`;
};






// Do not change anything below this line.
module.exports = {
Expand Down
66 changes: 66 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Creating a SCRATCH PAD FOR NOTES/IDEAS AND STEP GUIDE

//function getLongestDinosaur(dinosaurs) {}



// function getDinosaurDescription(dinosaurs, id) {
// for (let dino of dinosaurs) { // tried to use .find function for cleaner code but couldn't use it how i wanted it.
// if (dino.dinosaurId === id) {
// if (dino.mya.length === 2) { // used an if statement to check on the MYA and how many index's it had.
// return `${dino.name} (${dino.pronunciation})\n${dino.info} It lived in the ${dino.period} period, over ${dino.mya[1]} million years ago.`
// } else {
// return `${dino.name} (${dino.pronunciation})\n${dino.info} It lived in the ${dino.period} period, over ${dino.mya[0]} million years ago.`
// };
// };
// }; return "A dinosaur with an ID of '" + id + "' cannot be found."
// };


/*

// Return the name of the room where the given dinosaur can be found. If the dinosaur does not exist in the `dinosaurs` list or cannot be found in any room, return an error message that says so.
// *
// search through the dino list to compare name given with dinosaurs.diand dinosaurs.
// and rooms list rooms.name

// equate nameGiven w/ dinosaurs.dinosaursID w/ roooms.dinosaurs
// make vars for dinoId



// function getRoomByDinosaurName(dinosaurs, rooms, dinosaurName) {
// let target = null;
// let targetRoom = null;
// for( let dino of dinosaurs){
// if(dinosaurName === dino.dinosaurId){
// let target = dino.dinosaurId;
// } else return "Dinosaur with name '" + dinosaurName +"' cannot be found in any rooms"
// };
// targetRoom = rooms.find((room) => room.dinosaurs == target)
// if(target === targetRoom){
// return target.name
// }else {
// return "Dinosaur with name '" + dinosaurName +"' cannot be found."
// }
// };
// let theDinoFound = [];
// if(key){

// // // }
// return theDinoFound;
// }

// // for(let dino of dinosaurs){
// // if (dino.mya.length === 1 && (mya === (dino.mya[0]-1 )|| (mya === dino.mya[0]))){
// // theDinoFound.push(dino[target])
// // } else if (mya <= dino.mya[0] && mya >= dino.mya[1]){
// // theDinoFound.push(dino[target])
// // }
// // }

*/



console.log(calculateTicketPrice(tickets, ticketInfo))