© 2021 Matt Thomas

Interview Live Coding Exercise

also known as

Whiteboarding

Steps for success!

There are several steps that should be thought through during the problem solving process.

  1. Gather requirements

  2. Break down problem

  3. Write pseudocode

  4. Code a solution

  5. Test the solution

  6. Consider possible changes

Gather Requirements

The goal is the clarify the problem to the point that there are no more questions.

  • Asking too many questions is better than too few
  • Establish what your input and output should look like
  • Find edge cases
  • Establish programming language and expected structure
    • "script" file
    • Function
  • If not already provided, write out requirements

Break Down the Problem

  • Examine the question and determine if it can be broken down into small parts, such as "Write a function" or "If this then do that"

  • Once you have broken down the question, establish the priority of each part then work on each part in the appropriate order

Pseudocode

Pseudocode is a step-by-step description of an algorithm written in simple English using a code-like structure.

Use plain old English, like explaining your code to your Grandma.


Example:

Enter Value
If Value greater than 10
  Log "Your number is greater than 10"
If Value less than 10
  Log "Your number is less than 10"

Write a Solution

  • Write code! Finally!!!
  • Talk with your interviewer about what you are doing
    • THINK OUT LOUD
  • Mistakes are okay!
  • If handwriting code, be sure to write your code neatly

Test

  • If coding on a computer, execute your code after completion
  • Make sure to test edge cases
  • If handwriting code, walk through the steps of your code verbally

Consider changes

  • Review and fix any bugs after executing the code
  • Examine the code and discuss improvements

Rules/Expectations

  • Do NOT search for the solution for your specific question.
  • The use of any AI tools is strictly prohibited!
  • You may use the curriculum or MDN as a reference for JavaScript.
    You may also reference any code you have previously writing within the cohort including homework, class activities, class SPA and capstone repositories.
  • Each student will be expected to participate is delivering the following:
    • Requirements clarification & questions asked
    • Explanation of the code solution
    • Test the code
  • The entire class will discuss improvements & enhancements.

Question 1

Write a JavaScript function that takes in two integers and returns their sum, unless the two integers are equal. If the two integers are equal, then return three times their sum.


Examples:

sum2Integers(10, 20) // --> 30
sum2Integers(10, 10) // --> 60

Question 2

Write a JavaScript function that takes in an array of integers and returns the integer with the highest value.

(Do NOT use Math.max()!!!)

Example:

findHighest([4, 1, -3]) // --> 4

Question 3

Write a function that generates a random number between 0-10.

If the number is greater than 5, log “{number} is greater than five!”.

If it is less than 5, log "{number} is less than five!"


Examples

five() // --> 3 is less than five

Question 4

Write a function that counts the number of vowels in a string.

The vowels are "a", "e", "i", "o" & "u"


Examples:

countVowels('hello') // --> 2
countVowels('why') // --> 0

Question 5

Write a function that determines if a string is a palindrome.

A palindrome is a string that is the same forward and backwards.


Examples:

isPalindrome('racecar') // --> true
isPalindrome('table') // --> false

Question 6

Write a function that determines if a number is prime.

Examples:

isPrime(11) // --> true
isPrime(6) // --> false

Question 7

Write a function that accepts 2 arguments:
student name and indeterminate number of test scores

The function should output the name, scores and the average of the scores.

The output should be grammatically correct.

Example:

avgTestScores('John', 95, 70, 87, 82)
// --> John took 4 tests, earning these score(s): 95, 70, 87 and 82.
// --> That's an average score of 83.5.

Question 8

Write a code block that takes in an array of objects and draws buildings with the character provided.

Each building object definition shall have two required attributes: width and height and one optional attribute: char.

If the char attribute is not provided then it should default to: "#".

Example:

drawBuildings([
	{width: 2, height: 2, char: '%'},
	{width: 3, height: 5, char: '@'},
	{width: 1, height: 3}
])

Bonus Exercise

Complete the Thanksgiving Holiday Dinner Exercise

Thanksgiving Holiday Dinner

Additional Interview Questions