Skip to content

Instantly share code, notes, and snippets.

@mnichols
Created August 21, 2017 12:31
Show Gist options
  • Select an option

  • Save mnichols/52e24f57f3afae36e445fa3a0e5fee5b to your computer and use it in GitHub Desktop.

Select an option

Save mnichols/52e24f57f3afae36e445fa3a0e5fee5b to your computer and use it in GitHub Desktop.

Basic - intermediate JS exercises

  1. What value is now stored in the variable name?
var isKing = true;
var name = isKing ? ‘Arthur’ : ‘Hank’;
  1. What is the difference between == and === in Javascript?

  2. Write a function that takes two numbers as arguments and returns the sum of the two numbers in Javascript

  3. Write a function that takes an array as an argument and prints out the numbers in the array that are greater than 5 (for example foo([3,6,1,7]) would print out 6 and 7) in Javascript

  4. Write a for loop that will iterate from 0 to 20. For each iteration, it will check if the current number is even or odd, and report that to the screen in Javascript

  5. What does 'this' refer to when used in a JavaScript method?

  6. Create an object that has properties with name = "fred" and major="music" and a property that is a function that takes 2 numbers and returns the smallest of the two, or the square of the two if they are equal.

  7. What’s the result of executing this code and why?

function test() {
   console.log(a);
   console.log(foo());
   
   var a = 1;
   function foo() {
      return 2;
   }
}

test();
  1. Write a function to print out the song lyrics to "99 Bottles of Beer." Now add a case for when there are no bottles left.

  2. Write a function to mimic the game of Exploding Kittens using a standard 52 card deck with a single joker. Deal a random card to each player each turn. The game ends when someone is dealt the joker. Display a dialogue message to the losing player.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment