Skip to content

Instantly share code, notes, and snippets.

@jackychenhahahaha
Created September 20, 2019 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackychenhahahaha/1666c2afaea737b25bab1754c9c0e4b1 to your computer and use it in GitHub Desktop.
Save jackychenhahahaha/1666c2afaea737b25bab1754c9c0e4b1 to your computer and use it in GitHub Desktop.
Jianzhong (Jacky) Chen
function convertTo(units, num) {
//Do not worry about formatting your output to round to the nearest 2nd decimal number.
if (units === 'cm') {
return num * 2.54;
} else if (unites === 'in') {
return num / 2.54;
}
}
//=================================================
var cityZBusSchedules = {
bus12Schedule: [9, 18, 27, 36],
bus15Schedule: [11, 22, 33, 44],
bus22Schedule: [15, 30, 45]
};
function displayBusSchedule(cityZBusSchedules, busLine) {
if (busLine === 'bus12Schedule') {
console.log("The bus will arrive in the next " + cityZBusSchedules.bus12Schedule + " minutes.");
} else if (busLine === 'bus15Schedule') {
console.log("The bus will arrive in the next " + cityZBusSchedules.bus15Schedule + " minutes.");
} else if (busLine === 'bus22Schedule') {
console.log("The bus will arrive in the next " + cityZBusSchedules.bus22Schedule + " minutes.");
}
}
displayBusSchedule(cityZBusSchedules, 'bus15Schedule');
//=============================================
function addGenre(song, genre) {
song['genre'] = genre;
return song;
}
var song = {title: "Countdown", artist: "Beyonce", durationInSeconds: 212};
var genre = 'Blues';
addGenre(song, 'Blues');
//==============================================
function executiveSummary(email) {
if (email.length > 15) {
return email.substring(0, 15);
} else if (email.length <= 15) {
return email;
}
}
executiveSummary('URGreat!!!aaaaaaaaaaa');
//================================================
function removePartyKillers(playlist) {
for (var i = 0; i < playlist.length; i++) {
var songObj = playlist[i];
if (songObj.durationInSeconds > 480) {
delete(songObj);
}
}
return playlist;
}
var awesomePlaylist = [
{
title: "Hay Day",
artist: "Robo-Crop",
durationInSeconds: 378
}, {
title: "10,000 Pounds",
artist: "L-Ton Jonn",
durationInSeconds: 498,
}, {
title: "Caesar's Salad",
artist: "DJ Dinner Julius",
durationInSeconds: 600,
}, {
title: "The British Are On Their Way",
artist: "Raul Pevere",
durationInSeconds: 1095,
}, {
title: "13th",
artist: "The Doctors",
durationInSeconds: 185,
}
];
removePartyKillers(awesomePlaylist);
//=======================================
function onlyPayForHealthyThings(myCart) {
var priceSum = 0;
for (var i = 0; i < myCart.length; i++) {
var obj = myCart[i];
if (obj.nutritionalValue[lowSugar] === true && obj.nutritionalValue[lowSodium] === true) {
priceSum += obj.price;
}
}
return priceSum;
}
var myCart = [
{ name: 'chips',
nutritionalValue: { lowSugar: true, lowSodium: false },
price: 0.75 },
{ name: 'carrots',
nutritionalValue: { lowSugar: true, lowSodium: true },
price: 1.5 },
{ name: 'cookies',
nutritionalValue: { lowSugar: false, lowSodium: true },
price: 2.5 },
{ name: 'apples',
nutritionalValue: { lowSugar: true, lowSodium: true },
price: 0.6 },
{ name: 'soda',
nutritionalValue: { lowSugar: false, lowSodium: true },
price: 1.1 },
{ name: 'avocados',
nutritionalValue: { lowSugar: true, lowSodium: true },
price: 0.75 }
];
onlyPayForHealthyThings(myCart);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment