Code Monkey home page Code Monkey logo

functions_lab's Introduction

Functions Lab

  1. Write a function that prints "Hello, World!" to the console when called.

  2. Write a function that takes the name of a person as an argument, and says "Hello" to that person in the console.

  3. If your previous function did not use the return keyword, modify it so that it does. It should return the message to be logged instead of logging it directly. Store the result in a variable and log that instead.

    Bonus: Appreciate the difference between logging from within the function and returning a value to be logged outside the function.

  4. Write a function add() that takes two numbers as arguments and returns the sum.

    • Write a function sub() take takes two numbers as arguments and returns the difference.

    • Write a function combine() that takes three parameters. The first two are numbers and the last is a boolean. If the boolean is true, return the sum of the first two arguments, otherwise, return the difference. Hint: use add() and sub() from within combine().

  5. Write a function that prints out how many times it has been called.

    Hint: Can you do this using only local variables? Think about what we talked about regarding variable scope. Can you rely on the help of a global variable?

Bonus:

  1. Write a function to return true or false if a number passed in is a prime number.

  2. Write a function called merge. The function should take two sorted arrays of numbers as input and return a merged array of the sorted numbers from the input. For example, if the input arrays were var arr1 = [3,6,11]; var arr2 = [2,4,5,8,9]; Then the returned array would be: [2,3,4,5,6,8,9,11]. Avoid using any built-in sorting methods.

  3. Write a function called letterCount that takes a string and finds out how many times a character occurs. For example, if the input was "apple", the output should inform you that "a" occurred once, "p" occurred twice, and "l" and "e" each occurred once. You have some flexibility in how you want to output this data.

functions_lab's People

Contributors

tlicata avatar whoistim avatar

Watchers

 avatar  avatar

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.