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

im not done with the last question but it is what it is #14

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/src/03-ticket-calculator.js"
}
]
}
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,21 @@ const exampleDinosaurData = require("../data/dinosaurs");
* getLongestDinosaur(dinosaurs);
* //> { Brachiosaurus: 98.43 }
*/
function getLongestDinosaur(dinosaurs) {}
function getLongestDinosaur(dinosaurs) {
let longest = 0;
let longestDino = {};
if (dinosaurs.length === 0){
return longestDino;
}
for (let length of dinosaurs) {
if (longest < length.lengthInMeters ) {
longest = length.lengthInMeters
dinoName = length.name
}
}
longestDino[dinoName] = Number((longest * 3.28084).toFixed(2))
return longestDino;
};

/**
* getDinosaurDescription()
Expand All @@ -44,7 +58,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) {
for (let desc of dinosaurs) {
if (id === desc.dinosaurId) {
years = Math.min(...desc.mya)
return `${desc.name} (${desc.pronunciation})\n${desc.info} It lived in the ${desc.period} period, over ${years} million years ago.`
}
}
return `A dinosaur with an ID of '${id}' cannot be found.`;
}

/**
* getDinosaursAliveMya()
Expand All @@ -71,7 +93,22 @@ function getDinosaurDescription(dinosaurs, id) {}
* getDinosaursAliveMya(dinosaurs, 65, "unknown-key");
* //> ["WHQcpcOj0G"]
*/
function getDinosaursAliveMya(dinosaurs, mya, key) {}
function getDinosaursAliveMya(dinosaurs, mya, key) {
let addToArr = key;
let result = [];
for (let aliveDinos of dinosaurs) {
if (aliveDinos[addToArr]=== undefined) {
addToArr = "dinosaurId"
}
if (aliveDinos.mya.length === 1 && (mya === aliveDinos.mya[0] || mya === (aliveDinos.mya[0] - 1)) ) {
result.push(aliveDinos[addToArr])
}
else if (mya <= aliveDinos.mya[0] && mya >= aliveDinos.mya[1]) {
result.push(aliveDinos[addToArr])
}
}
return result;
}

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,22 @@ 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) {
for (let dino of dinosaurs) {
if (dinosaurName === dino.name){
id = dino.dinosaurId;
for (let dinosRoom of rooms){
roomName = dinosRoom.name;
if (dinosRoom.dinosaurs.includes(id)){
return roomName;
}
}
return `Dinosaur with name '${dinosaurName}' cannot be found in any rooms.`;
}
}
return `Dinosaur with name '${dinosaurName}' cannot be found.`;
}


/**
* getConnectedRoomNamesById()
Expand All @@ -49,7 +64,28 @@ function getRoomByDinosaurName(dinosaurs, rooms, dinosaurName) {}
"Kit Hopkins Education Wing"
]
*/
function getConnectedRoomNamesById(rooms, id) {}
function getConnectedRoomNamesById(rooms, id) {
let connectedTo = [];
let connected = {};
for (const conRoom of rooms) {
connected[conRoom.roomId] = conRoom.name;
//put all the room names in an object with the key being the roomId
}
if (!connected[id]) {
return `Room with ID of 'incorrect-id' could not be found.`;
}
let myTarget = rooms.find(conRoom => conRoom.roomId === id);
// .find will search through the entire array, use the key work conroom, and equal it to my target only if the roomId matches the given Id
for (let roomId of myTarget.connectsTo) {
//looping through the array of connectsTo inside of the conRoom that has matches the Id given
if (!connected[roomId]) {
return `Room with ID of 'incorrect-id' could not be found.`;
}
connectedTo.push(connected[roomId]);
//if the room has an Id that is inside of the room we're trying to find connections for, were giving back that name inside of our array
}
return connectedTo;
}

module.exports = {
getRoomByDinosaurName,
Expand Down
43 changes: 41 additions & 2 deletions src/03-ticket-calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,30 @@ const exampleTicketData = require("../data/tickets");
calculateTicketPrice(tickets, ticketInfo);
//> "Entrant type 'kid' cannot be found."
*/
function calculateTicketPrice(ticketData, ticketInfo) {}
function calculateTicketPrice(ticketData, ticketInfo) {
let ticketPrice = 0;
const {ticketType, entrantType, extras } = ticketInfo;
if (!(ticketType in ticketData)) {
return `Ticket type '${ticketType}' cannot be found.`
}
else if (!ticketData[ticketType].priceInCents[entrantType]) {
return `Entrant type '${entrantType}' cannot be found.`
}
else if (ticketData[ticketType].priceInCents[entrantType]){
ticketPrice += ticketData[ticketType].priceInCents[entrantType]
if (extras.length > 0) {
for (const ex of extras) {
if (!(ex in ticketData.extras)) {
return `Extra type '${ex}' cannot be found.`;
}
if (ticketData.extras[ex].priceInCents[entrantType]) {
ticketPrice += ticketData.extras[ex].priceInCents[entrantType];
}
}
}
return ticketPrice
}
}

/**
* purchaseTickets()
Expand Down Expand Up @@ -109,7 +132,23 @@ function calculateTicketPrice(ticketData, ticketInfo) {}
purchaseTickets(tickets, purchases);
//> "Ticket type 'discount' cannot be found."
*/
function purchaseTickets(ticketData, purchases) {}
function purchaseTickets(ticketData, purchases) {
receipt = "Thank you for visiting the Dinosaur Museum!\n-------------------------------------------\n";
for (const purchase of purchases){
tickPrice = purchase
// set ticket price to equal one object inside of the purchases array
price = calculateTicketPrice(ticketData, tickPrice)
// set price to equal the results of the calculate price function
if (typeof(price) === "string"){
return price
// if the results are a string, this means its an error message, and we should return the error message immeadiately
}
tickPrice = price.toLocaleString("en-US");
// if its not a string, then it can only be a number, and so we are converting the price to a US dollar, and reassigning tickPrice to equal the US dollar amount

}
return receipt
}

// Do not change anything below this line.
module.exports = {
Expand Down