For this lab we would like you to complete the following exercises in CoffeeScript. You can do this in a Rails app or in a seperate coffee file.
Define a function reverse()
that reverses a string. For example, reverse("building")
should return the string "gnidliub"
.
Write a function filterLongWords()
that takes an array of words and an integer i
and returns an array of words that are longer than i
.
Write a function range
that takes one argument, a positive number, and returns an array containing all numbers from 0 up to and including the given number.
Write a function called startsWith
that takes two arguments, both strings. It returns true
when the first argument starts with the characters in the second argument, and false
otherwise.
Write a function named assignGrade
that:
- takes 1 argument, a number score.
- returns a grade for the score, either "A", "B", "C", "D", or "F".
Call that function for a few different scores and log the result to make sure it works.
Write a function named pluralize
that:
- takes 2 arguments, a noun and a number.
- returns the number and pluralized form, like "5 cats" or "1 dog".
Call that function for a few different scores and log the result to make sure it works.
Store a celsius temperature into a variable. Convert it to fahrenheit and output "NN°C is NN°F".