Git Product home page Git Product logo

interview-challenge-practice-a's Introduction

Foundations -> Practice Version 2 challenge

Introduction

This document contains the requirements for completing your interview challenge as well as instructions for setup and teardown. Read the following content carefully!

Setup

Completed by your interviewer:

For you to complete:

First, we'll need to navigate to the directory on the interview USB drive where the challenge files are. On a mac, you'll find it here:

cd "/Volumes/INTERVIEW/[YOUR DIRECTORY NAME]"

Next, we need to setup the challenge. You can do so by simply running a script:

cd setup && npm run setup && cd ..

The folders for each part of this challenge contain a package.json that specifies the dependencies for that part. You can quickly install dependencies for all parts of the challenge by running this script:

cd setup && npm run install:all && cd ..

Accessing the Database

A database connection string has been set in the .env file at the top level of this repository. You can use this to connect to the database using any client you wish.

If you would like to use Postico to access the database you can simply use the .pgfav file in the interview root directory to automatically add the database connection configuration. Use the following command:

open postico-db-practice-a.pgfav

The Interview Challenge

This challenge has three parts:

  • Part 1: Create a function that uses pg-promise to execute a SQL query from within a Node.js program
  • Part 2: Using Express, implement handling for a GET route that renders (returns markup for) an HTML page using a template engine (Pug or EJS)
  • Part 3: Remove a row from a html page using javascript

Part 1: SQL

PostgreSQL, Node.js, & pg-promise

Create a function in the file db.js called getFlightPassengers.

The function should accept a string parameter named flightNumber. It should use the pg-promise database client (already instantiated) and return a promise that resolves to the result of the query (an array of objects containing the names of all passengers on that flight. The property for the passenger name values in these objects should be called name).

Sample result:

  [ { name: 'Michael Jackson' },
    { name: 'Tito Jackson' },
    { name: 'Jackie Jackson' },
    { name: 'Baby Spice' },
    { name: 'Scary Spice' } ]
  • 5: The function takes a parameter called flightNumber.
  • 5: The function executes a SQL query using pg-promise
  • 5: The query uses index variables (e.g. $1) to make the query dynamic
  • 5: The function returns a promise which resolves to the result of the query.
  • 20: The result set of the SQL query includes one row containing a passenger name field for every passenger on the specified flight number.

ER Diagram

An ER diagram has been provided that visualizes the database schema:

ER Diagram

Part 2: Express

GET route

Implement handling for a route/endpoint GET /flight_roster. It should accept a query string parameter flightNumber -- a string value representing a flight number. Use the getFlightPassengers function provided in db.js to retrieve the list of passengers on the specified flight.

  • 5: Route is a GET route
  • 5: Route accesses the flightNumber query string parameter successfully
  • 5: Route uses the provided getFlightPassengers function to retrieve the passenger data
  • 10: Route passes data to the EJS or Pug template.
  • 10: The template contains code to correctly render the list of passengers retrieved.
  • 10: The template contains code to correctly display the text An error occurred in the div with the id message, in the case of a server error.
  • 10: A GET /flight_roster request can be executed using a browser without error.
Starting the server

To start the server, run: npm start.

Part 3: Front-End

DOM Manipulation

In this section, the scaffolding has been created for the /flight_roster route described in Part 2. Choose a template engine (EJS or Pug) in app.js, then make a GET request for the /flight_roster resource. Include the query string flightNumber=1147A to retrieve passengers for that specific flight.

The challenge for this section: when a user clicks the button labeled Give passenger a parachute, one of the passengers (it doesn't matter which one) should be removed from the list. Note: The passenger only needs to be removed from the page. There is no need to update the database or communicate with the server in any way.

You may use vanilla JS or jQuery.

  • 5: Code is written in flight_roster.js, not inline in the template file.
  • 10: The code uses JavaScript or jQuery to access the Give passenger a parachute button DOM element.
  • 10: The Give passenger a parachute button has an on click event listener.
  • 10: The event listener callback removes a row upon the first click.
  • 10: The passenger list has one fewer row after each click.
  • 10: If the list is empty when the button is clicked, the page displays a message in the div with the id message: "All out of passengers".
Starting the server

To start the server, run: npm start.

Teardown

Let's do a little cleanup:

  1. End the video recording (if applicable)
  2. From your terminal, stop any running express servers
  3. From your terminal, cd out of the usb drive directory
  4. Quit your terminal application
  5. Close any browser windows pertaining to the challenge
  6. Remove the Postico entry for the database connection (if applicable)
  7. Quit your text editor application
  8. Eject the USB drive (diskutil unmount INTERVIEW)

interview-challenge-practice-a's People

Contributors

justinhaaheim avatar

Watchers

James Cloos avatar Anne avatar Aaron Xavier avatar Kamrin Klauschie avatar  avatar Learners Guild Bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.