Elements of JS: Functions (Part 1)

Welcome to your first exercise. While I am going to assume you have Node and Yarn installed on your computers, and you have basic knowledge of Git, I am going to explain step by step how to get everything set-up and how to get "unit tests" running.

Requirements

  • Node
  • Yarn
  • Git

Instructions for running tests

  1. We need to open our Terminal and navigate to the folder where we want to save our exercises. (Some of the key commands for navigation in Unix systems are cd and ls)
  2. Once you are in the right directory, you are going to git clone the repo. Running this command will download the repository into the current directory.
git clone https://github.com/reneloperena/elements-of-js-functions-p1.git
  1. Navigate inside the folder
  2. Run yarn to install our dependencies. This repository uses libraries such as Jest and Babel; we'll learn more about JavaScript modules in the future, for now, know that everytime you download a Repo, you need to run yarn to download its dependencies.
yarn
  1. To run the tests, you can run our test script using
yarn run test
  1. Start modifying the hello.js file until all tests pass.

Exercises

  1. In hello.js you need to define a function called sayHello that takes a name as a parameter and returns the string 'Hello {name here}!'.
  2. In temperature.js:
  • Define a function named fahrenheitToCelcius which will take a value (number) in degrees fahrenheit and convert it to celsius
  • Define a function named celsiusToFahrenheit which will do the same as the previous function but convert it from celsius to fahrenheit.
  • Define a function named friendlyCelsiusToFahrenheit which will take a value in celsius and convert it to a string that contains the following: '{value in C} Celsius equals to {value in fahrenheit} Fahrenheit'
  1. (BONUS) Find out what are Template Literals in JavaScript and change your code to use them. (Mozilla Developer Network is a great place to find information about JavaScript)