CPSI 20023      HW5           Due by Monday, Oct. 5, 2026

Please email your assignment to: IFSC30003HW@gmail.com. You can paste most of your answers into the email itself, but some may need to be attachments.

 

1. Declare one function one way and the other a second way. One way is the common way that starts:

    function myFunc1.........


Type the definition of myFunc1 here:

     The other way shows what happens "under the hood" when declaring a function:

    let myFunc2=.........


Type the definition of myFunc2 here:

     Declare a variable x, set it to the value of myFunc2, and run function x.

     The typeof of 5 is number. What is the typeof of variable myFunc2?

Using a sandbox, show the typeof x.

Hand in a full-screen screenshot of the two function definitions you typed in above, and another full-screen screenshot of the sandbox showing the code containing the call to typeof x and the result of running it.

2. Make a function that calls itself once. Try to do it yourself before asking an AI for hints. If you do ask an AI, give it your partial code and ask for hints, rather than just asking it to give you the answer. This way you will learn something! Hand in the source code, and an explanation of if/how you used AI to help.

3. Recall the Fibonacci number calculating function shown in class. Each call calls itself twice (except for when a termination condition activates). This causes exponential computational complexity: fib(n+1) takes about 1.6x as long to run as fib(n). This can be used to measure the speed that a browser can run JS code on your computer. Just try the function for different values of n and find a value of n that takes about 5 seconds to run. Try that same value in another brand of browser. To hand in the answer to this question, move an size your two browser windows so they show side by side on your screen, and then hand in a full-screen screen shot. Also give the two run times and note which browser was faster.

4. Call a function and print the result provided by the return statement. Then comment out the return statement. In your answer, say what it prints, and give the source code.

5. Make a short program that prints out the code of a function (that is, instead of calling the function, it prints the code of the function). Hand in screen shot of a sandbox showing the program and also the code that it printed out.

6. Declare an array. Print out its elements using a loop. Print out the length of the array. Hand in the code and the output.

7. Use https://claude.ai/public/artifacts/dd16d396-501c-4290-a680-94eb8bf111e4. Hand in a screen shot showing the final output.

8. Make a simple game in a web page containing Javascript. You can build on a game handed in for a previous HW or not, it's up to you. The game should help the player to learn about JavaScript arrays, focusing on the basics for students who are learning the basics of arrays in JS.