Retake of LG Phase-2-Challenge
This is the challenge for getting into phase 2.
To get started, create a new repository called phase-2-challenge-c
. Do all of your work in this repo and submit it as your solution.
Skills covered:
- Programming
- Programming in JS
- Testing
- Node.js
- HTML & CSS
- Terminal, Bash, & UNIX
Each requirement has a point value. A fully complete requirement gets full points; partially complete requirements get partial points; incomplete requirements get no points. Completeness is determined by calculating points earned divided by total points available.
- 10: Solution is in a public GitHub repository called
phase-2-challenge-c
. - 10: Solution repository has 4 folders:
part-1
,part-2
, andpart-3
, andpart-4
. - 20: Git history shows frequent commits.
For the following exercises, write your functions in a file called part-1/functions.js
and your tests in a file called part-1/tests.js
.
You can use whichever testing tools you prefer: console.assert()
(builtin to Node), Mocha and Chai, Jasmine, etc.
Write a function weekday(date)
to find the day of the week for a given Date
object, returing the weekday as a string ('Sunday', 'Monday', 'Tuesday', etc.).
Example:
let dateA = new Date(2017, 5, 15) // June 15, 2017
weekday(dateA) // returns "Thursday"
let dateB = new Date(2017, 11, 31) // Dec 31, 2017
weekday(dateB) // returns "Sunday"
- 10: A test using expected/valid inputs for the
weekday()
function is written intests.js
. - 10: A test using unexpected/invalid inputs for the
weekday()
function is written intests.js
. - 30: Correct implementation of the
weekday()
is defined infunctions.js
. - 10: Tests for
weekday()
are passing.
Write a function capitalizeFourth(string)
that takes a string of words and returns the same string with every 4th character converted to upper case and the rest converted to lower case. Treat whitespace and punctuation characters the same as any other word character.
Example:
capitalizeFourth("Eenie, Meenie, Miney, Moe") // => "eenIe, MeenIe, MineY, mOe"
capitalizeFourth("ABRACADABRA") // => "abrAcadAbra"
- 10: A test using expected/valid inputs for the
capitalizeFourth()
function is written intests.js
. - 10: A test using unexpected/invalid inputs for the
capitalizeFourth()
function is written intests.js
. - 30: Correct implementation of the
capitalizeFourth()
is defined infunctions.js
. - 10: Tests for
capitalizeFourth()
are passing.
Write a function getValues(obj)
that returns all the values for an object (i.e. the values for each of its properties). Ignore symbolic properties and count only the "own properties" (not inherited) of the object.
Example:
let person = {
name: 'Dominique',
age: 30,
phone: '555-555-5555'
}
getValues(person) // => ['Dominique', 30, '555-555-5555']
getValues({ ids: [4, 8, 2], success: true }) // => [ [4, 8, 2], true ]
getValues({}) // => []
- 10: A test using expected/valid inputs for the
getValues()
function is written intests.js
. - 10: A test using unexpected/invalid inputs for the
getValues()
function is written intests.js
. - 30: Correct implementation of the
getValues()
is defined infunctions.js
. - 10: Tests for
getValues()
are passing.
Write a function filterAround(array, lower, upper)
that takes an array of strings, a lower
value, and a upper
value. It returns a new array containing only the elements from the source array
that come before lower
alphabetically and after upper
. The elements in the returned array should be in the same order as the source array.
Example:
let animals = ['dog', 'cat', 'zebra', 'ape', 'lion', 'cow']
filterAround(animals, 'cow', 'dog') // => ['cat', 'zebra', 'ape', 'lion']
filterAround(animals, 'chimp', 'lobster') // => ['cat', 'zebra', 'ape']
filterAround(animals, 'aardvark', 'zebu') // => []
- 10: A test using expected/valid inputs for the
filterAround()
function is written intests.js
. - 10: A test using unexpected/invalid inputs for the
filterAround()
function is written intests.js
. - 30: Correct implementation of the
filterAround()
is defined infunctions.js
. - 10: Tests for
filterAround()
are passing.
Write a Node.js script to search for data from a JSON file.
Use the cars.json
file provided representing a database of cars in a used car lot. Download the file to your part-2/
folder.
Then write two scripts that can be run using the node
command.
searchInYears.js
takes one argument (let's call ityearRange
), finds all the cars fromcars.json
which have ayear
that is within theyearRange
, and prints theid
,make
,model
, andyear
of each matching car. The year range format should follow the formatYYYY-YYYY
, e.g.1995-2001
.searchByModel.js
takes one argument (let's call it themodel
), finds all the cars fromcars.json
who have amodel
value that exactly matches themodel
argument, and prints theid
,model
,year
,last_owner
, anddate_purchased
of each matching car.
Your searches should not be case-sensitive: i.e. a search for "sorento" is the same as a search for "Sorento".
Example: searchInYears.js
$ node searchInYears.js 1999-2000
Finding cars from 1999 to 2000...
[ { id: 21, make: 'Toyota', model: 'Land Cruiser', year: 1999 },
{ id: 23, make: 'Ford', model: 'Mustang', year: 1999 },
{ id: 26, make: 'Chevrolet', model: 'Metro', year: 2000 },
{ id: 62, make: 'Chrysler', model: 'Sebring', year: 2000 },
{ id: 79, make: 'Chevrolet', model: 'Impala', year: 2000 },
{ id: 85, make: 'Dodge', model: 'Grand Caravan', year: 1999 },
{ id: 92, make: 'Nissan', model: 'Quest', year: 1999 } ]
Example: searchByModel.js
$ node searchByModel.js jetta
Finding cars with model "jetta"...
[ { id: 1,
model: 'Jetta',
year: 2011,
last_owner: 'Kaylil Minico',
date_purchased: '7/3/2016' },
{ id: 32,
model: 'Jetta',
year: 1995,
last_owner: 'Katerine McEllen',
date_purchased: '1/8/2004' } ]
- 40:
searchInYears.js
script prints the carid
,make
,model
, andyear
for all cars with a year inside the year range provided in the script argument. The range is inclusive—i.e. include cars with the same year as the start year or the end year of the range, as well as all years in between. - 40:
searchByModel.js
script prints the carid
,model
,year
,last_owner
, anddate_purchased
for all cars with amodel
that matches the provided argument (ignoring case).
Write the HTML & CSS to layout a page for an online bookstore.
You only need to write HTML & CSS. No JavaScript or web server is required.
Design a layout to match the following wireframe:
- 10: All files are stored under the
part-3/
folder - 20: No third party CSS libraries are used (all code must be written from scratch)
- 10: HTML and CSS are separated into their own files.
- 20: Page has a full-width header with the site title "Bookstore" and a button "Book bag (3)"
- 10: Site title "Bookstore" is aligned to the left side of the header
- 10: "Book bag (3)" button is aligned to the right side of the header
- 20: Page has a "Shelves" sidebar with all shelves for books
- 10: Page has a main content area showing each of the books
- 10: Main content organizes all books by shelf
- 20: Main content lists books' name, author, and a "Buy" button
- 20: Clicking on a shelf in the "Shelves" sidebar will jump to that shelf
Copy the questions below into a file part-4/quiz.md
. Then, write your answer to each question directly below it.
The quiz is worth 50 points in total.
Reminder: you can use the internet to help you answer these questions :)
-
What is the PATH environment variable used for in UNIX systems?
-
On a UNIX computer, how do you stop a running process?
-
Which command can you use to see which homebrew packages you've installed?
-
On a UNIX computer, how do you find the process id of a running process?
-
In a terminal, what does control-c do?
-
What would be the result of typing the following commands?
$ cd /Users/lucy $ mkdir one $ touch alpha $ cd one $ touch alpha $ pwd
-
How do you see which environment variables are set in your shell?
-
What keyboard shortcut do you use to perform a "Find" search in your editor?
-
How do you see which aliases you have in your shell?
-
When a terminal command completes, how can you tell if it was successful or not?
-
What does your
~/.gitconfig
have in it? (paste the whole file here) -
What is the difference between a relative and absolute path?
-
Lets say you have the following file structure
~ └── Projects ├── airbnb-for-llamas │ └── package.json └── facebook-for-mimes ├── README.md └── package.json
And you were in the
facebook-for-mimes
folder. What command would you use to copy theREADME.md
file to theairbnb-for-llamas
folder? -
What keyboard shortcut do you use in your editor to quickly navigate to a file in the current project?
-
Give an example of a file or folder pattern you commonly add to a .gitignore file and why you add it
-
What are the main differences between
Array.sort
andArray.filter
in JavaScript?
- 50: All questions are answered correctly.