Lab 8 - Anon Functions & Callbacks

Challenge

In this lab, we are getting familiar with JavaScript anonymous functions and callbacks.

Problems

I had some issues trying to figure out how to use an anonymous function with map() because I thought I was supposed to replace "function" with a function name and so I kept getting this error that said that I was missing a parenthesis when that wasn't really the case. (This can be seen in my screenshot for Task 1.) I also didn't quite understand the map() method too well until I played around with it and read up on it on w3schools.com. I also didn't conceptually understand what callbacks were despite probably already having used them in my previous coding experience. I think I finally get them though. They're functions that are being used as a parameter to another function and that main function then "applies" the callback function to its own parameters.

I also struggled with trying to do the bonus task of making the code results show. Luckily, this helped with understanding how to put all the information that was given in the lecture and in the assignment together to make the results show. Also I couldn't get the code to work with using <div> so I had to change that and use <p>.

Results

I have a Lab 8 index.html file that is styled with CSS and a JavaScript file that operates on numbers using anonymous functions and callbacks.

Script Output

Original:


Squared:


Rooted:


What numbers of the original are prime?


Check the console or



Timer

It's not perfect as I can't figure out how to add a "0" when it is a single digit, but I used setInterval() which uses a callback function I made called changeTimer().

Click to view images in a new tab! Image gallery code from w3schools.com.