Skip to content

Instantly share code, notes, and snippets.

@MicFin
Last active January 17, 2020 19:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save MicFin/891e003ec08aa59aeb77a4a69da2e5b1 to your computer and use it in GitHub Desktop.
Save MicFin/891e003ec08aa59aeb77a4a69da2e5b1 to your computer and use it in GitHub Desktop.
JS Functions Challenges

Javascript Function Challenges

  1. Create a program that will add two numbers and return the answer
    add(1,2) // should return 3
  2. Create a program that will add or subtract two numbers and return the answer
    calculator(1, 2, "add") // should return 3
    calculator(1, 2, "subtract") // should return -1
  3. Create a program that will get the sum of the numbers between 1 and n and return the answer
    summation(5) // should return 15 because 1+2+3+4+5=15
  4. Create a program to get the average of a group of numbers
    avg([8, 2, 2, 4]) // should return 4
  5. Create a program to get the sum of all the even numbers in a group
    summationEven(5) // should return 6 because 2+4=6
  6. Create a program to reverse the letters in a word
    reverse("caterpillar") // should return "rallipretac"
  7. Create a function that takes an array of words and combines them with a dash
    addDashes(['test1', 'test2', 'test3']) // should return "test1-test2-test3"
  8. Function that will count up to a number and back down and return a string of the climb
    countUpAndDown(3) // should return "1 2 3 2 1"
  9. Write a function that will tell you all of the words in an array that contain the letter a
    wordsWithA(['cat', 'rabbit', 'dog', 'frog']) // should return ['cat', 'rabbit']
  10. Function that returns the longest word in sentence
    longestWord("The cat in the house") // should return "house"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment