hw2.js
.(YOUR NAME)
with your name (without the parentheses) in the comment near the top of hw2.js
.hw2-demo.html
in your browser to experiment with my solution.hw2.html
in your browser to test your solution. Remember to save your file in VS code and reload your hw2.html
in your browser as you continue to test your work....
. Remove the ellipses once you are finished with that part of the assignment.hw2.js
file via MySLCBegin by trying the demonstration version. Each of the six buttons correspond to one of six pure functions. Your job is to “reverse engineer” each and then write your own version of that function. The file hw2-io.js
supplied with the starter archive contains the JavaScript functions invoked by clicking the buttons as specified in hw2.html
. Each of those functions is a wrapper around a corresponding pure function. For example, the second, button, labeled “go, GO, GO!” invokes the smallBigBigTester
function (defined in hw2-io.js
) which prompts the user for some text, passes that string as an argument to the pure function smallBigBig
(partially defined, but needs to be completed, in hw2.js
) which should return another string back to smallBigBigTester
which then displays the resulting string using alert
.
Here are the input and return types of the six pure functions you need to complete:
isInt
takes as input a number and returns a Boolean value.
smallBigBig
takes as input a string and returns another string.
isUniformCase
takes as input a string and returns a Boolean value.
bigEvenMedium5
takes as input a number and returns a Boolean value.
parity
takes as input three Boolean values and returns another Boolean value.
mystery
takes two inputs, the first a string, the second a number, and returns a Boolean value.
Once you understand what each function is supposed to accomplish, replace the ...
comment above that function with a comment of your own (that might run for several lines) explaining in concise, but grammatical and proofread prose what you think the function computes. (Follow examples from lab.)
Once you have explained what a function does in your own words, you can write the code representing its body. Test your code thoroughly both by evaluating some examples in the console and by clicking the buttons that use the wrappers to call the pure functions you are implementing. Remember to reload the page in your browser each time after modifying hw2.js
.
Remember, all of the functions should be pure: they take one or more arguments and return a value. Make sure that your functions have a single return statement as the last statement within the body of the function. Keep the return
simple: just return a variable. Use variable assignments to compute your result. Each function should have at least one let
assignment.
Your code should not use alert
, prompt
, or confirm
.
With numbers, you can use the standard five arithmetic operations:
+ - * / %
and the six arithmetic comparison operations:
=== !== < > <= >=
With Boolean values s you can use the literals true
and false
and the three standard Boolean operators:
! && ||
With strings, you can use:
=== !== .length .toLowerCase() .toUpperCase()
To experiment more directly with my solution, you can open up on a console while viewing this page and try examples such as:
> isInt(5)
true
> smallBigBig('yikes')
"yikes, YIKES, YIKES"
> isUniformCase('Not!')
false
> bigEvenMedium5(25)
true
> parity(false, false, false)
true
> mystery('bad', 4)
false