Practice with JavaScript

How well did you learn what's been taught in the previous lessons?

Scroll down...




In this assignment, you'll need to wrangle the syntax you just learned to solve a series of logical challenges. We've built a skeleton web page which will allow you to test what you've written.

Getting Started

  1. Fork and clone the main Github Repo.
  2. Open the index.html file in your browser to see our test suite. Refresh the browser to re-run the test suite.
  3. Open the JavaScript console so you can view output messages and debug.

Basic Problems

Your challenge is to build a JavaScript function which solves each of the following problems. The HTML file provided (index.html) will show you your outputs.

All of your functions should be contained within the object called sprintFunctions which is located in the scripts.js file.

  1. largestEl takes an array and returns the largest element.
  2. reversed takes a string and reverses it.
  3. loudSnakeCase takes a full sentence and puts it into "Loud_Snake_Case" format but strips out any non-character elements (like punctuation).
  4. fizzBuzz takes an input of a number and returns an array containing all the elements from 1 to that number. Each element divisible by 3 is replaced by "FIZZ", each element divisible by 5 is replaced by "BUZZ" and each element divisible by both 3 and 5 is replaced by "FIZZBUZZ". Eg. fizzBuzz(6) => [ 1, 2, "FIZZ", 4, "BUZZ", "FIZZ" ]
  5. compareArrays takes two arrays and checks to see if they are equal (same contents in the same order). Assume they're not nested.
  6. myMap takes an array and a function. It passes every element from the array into that function, in turn, running the function. The returned array should be filled with each of the return statements from that function.
  7. primes takes a number and outputs an array containing all prime numbers that occur prior to that number, e.g. primes(8) => [2,3,5,7]

Bigger Problems

The following challenges will require a bit more firepower than before and we haven't provided you with the test cases to make them happen.

  1. Build a Roulette game using basic object-oriented programming principles in JavaScript. The user should start with a bankroll and bet with each "spin" of the imaginary wheel. They can choose numbers 1-36. After each spin, the result is displayed and funds are distributed accordingly (payout is 35:1). Gameplay might look something like:

    r = new Roulette( 100 )  // starting bankroll $100
    r.spin( 10, 24 )         // bet 10 on 24
    // You Win $350, the spin was 24!!!
    // You now have $440.
    r.spin( 50, 13 )
    // You Lose, the spin was 11 :(
    // You now have $390
    // You now have $390
    r.buyIn( 1000 )
    // You bought in $1000
    // You now have $1390
  2. Add the ability for users of your Roulette game to bet on "0" (35:1), "00" (35:1), "Even" (1:1), "Odd" (1:1), "1 to 18" (1:1), "19 to 36" (1:1), "1st 12" (2:1), "2nd 12" (2:1), or "3rd 12" (2:1).

  3. (Optional): Build a simple Checkers (aka "Draughts") game in a similar fashion to your Roulette. Save the more advanced features like creating "King" pieces for last.

Finishing Up

  1. Commit, push, and pull request to the main repo.
Pull request 300 Octocat 300

Sign up to track your progress for free

There are ( ) additional resources for this lesson. Check them out!

There are no additional resources for this lesson just yet!

Sorry, comments aren't active just yet!

Next Lesson: Introduction to ES6 Tips and Best Practices