Giter Site home page Giter Site logo

functions_and_scope_assignment's Introduction

Function Exercises

Question 1

Write a function that returns the largest of two numbers. If they are equal, return the second one.

Example:

Input: 12, 4

Output: 12

Question 2

Write a function named getDogAge that takes one argument: a dog's age in human years. The function returns the dog's age in dog years. The conversion rate is 1 human year to 7 dog years.

Example:

Input: 4

Output: 28

Question 3

Write a function arraySum that takes in an array and returns the sum of all the elements.

Example:

Input: [13,2,4,-2]

Output: 17

Question 4

Write a function that takes in any two numbers and return their sum.

Example:

Input: 14, 5

Output: 19

Question 5

Write a function takes in any number grade and returns a corresponding letter grade.

Number Grade Equivalent Letter Grade
100 A+
90 - 99 A
80 - 89 B
70 - 79 C
65 - 69 D
Below 65 F

Example:

Input: 88

Output: "B"

Question 6

Implement a function named repeatLog that takes a string and a number as parameters. The function should log message count number of times.

Example:

Input: "+", 10

Output: ++++++++++

Question 7

Write a function named first that takes a number and returns an array with all the numbers from 1 to n

Example:

Input: first(3)

Output: [1, 2, 3]

Question 8

Write a function that logs the numbers from 1 to x, except:

If the number if a multiple of 3, log "Fizz" instead of the number If the number is a multiple of 5, log "Buzz" instead of the number If the number is a multiple of 3 AND 5, log "FizzBuzz" instead of the number Your function should take in one parameter: x (the number to count up to)

Question 9

Write a function named reverse that takes an array as a parameter. The function should return an array in reverse order.

Example:

Input: reverse([1, 2, 3])

Output: [3, 2, 1]

Question 10

Write a function that prints out the most frequently occurring element in an array.

Example:

Input: [2,1,4,2,5,2,3,23,3,3,2,2,2,24,56,2,2,5,46,2]

Output: 2

Question 11

Write a function that sums all the even numbers in an array.

Example:

Input: [1,2,5,64,23,22,91,3]

Output: 88

Question 12

Write a function that flips an object. All of the keys are now values and all of the values are now keys.

Example:

Input: {1: "uno", 5: "cinco"}

Output: {"uno": 1, "cinco": 5}

Question 13

Write a function that determines if a value is inside of array.

Example:

Input: [1,4,6,9,10], 5

Output: false

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.