Hey there! Are you ready to get your hands dirty with some code?
In order to complete these exercises, open repl.it and write your code in the left-hand panel. You can run your code using the "Run" button.
Need help? Grab an instructor, use Google search, or talk to your neighbor!
The lesson slides for this workshop can be found here.
-
Define a function named
calculateTipand give it two arguments:totalandpercent -
Inside your function, use the
returnkeyword to output a tip according to thepercentargument.
Extra Credit: Want to shave off the extra decimal places? Click here to learn about the .toFixed() function and how to use it.
In the example below, your function should output 7.965. It should not output '8.25'.
calculateTip(44.25, 18)-
Define a function named
removePrefixand give it one argument:url -
Inside your function, return the url without "www." included. Hint: Use
.slice
Hint: Don't forget to wrap quotes around your strings!
In the example below, your function should output google.com.
removePrefix('www.google.com')-
Define a function named
randomNumberGenwith no arguments. -
Inside your function, return a random number between 1 and 10. Hint: Use
Math.random()andMath.floor(number)
In the example below, your function should output a whole number between 1 and 10.
randomNumberGen()-
Define a function named
reverseSentencewith one argument:sentence -
Inside your function, return the reversed copy of the
sentencethat is passed in as an argument. Hint: UseString.split()Array.reverse()andArray.join()
In the example below, your function should output "!ecnetnes emosewa na si sihT".
reverseSentence('This is an awesome sentence!')