A small collection of JavaScript functions grouped into three categories and rendered in a simple web page:
- String manipulation
- Array utilities
- Mathematical helpers
The page displays sample results for each function so you can quickly verify behavior in the browser.
.
├─ index.html # Web page that loads and displays the results
├─ main.js # All functions + small UI to show sample outputs
└─ style.css # Minimal styling for cards and layout
reverseString(str)→ string: reverse the characters of a string.countCharacters(str)→ number: return the number of characters.capitalizeWords(sentence)→ string: capitalize the first letter of each word.
findMaximum(arr)→ number | undefined: largest value (undefined for empty arrays).findMinimum(arr)→ number | undefined: smallest value (undefined for empty arrays).sumOfArray(arr)→ number: sum of elements (treats array as numbers).filterArray(arr, condition)→ Array: elements that satisfy the predicate.
factorial(n)→ number | undefined:n!forn ≥ 0(undefined for negativen).isPrime(num)→ boolean: primality test with sqrt optimization.fibonacciSequence(terms)→ number[]: sequence with given number of terms.
Edge cases handled:
- Empty arrays for min/max →
undefined. - Negative factorial input →
undefined. - Fibonacci
terms <= 0→[];terms === 1→[0].
You only need a browser.
-
Double‑click
index.htmlto open it in your default browser.- You should see three sections (cards) with computed results.
-
Optional (recommended): use VS Code + Live Server
- Install the "Live Server" extension.
- Right‑click
index.html→ "Open with Live Server". - Any edits to
main.jsorstyle.csswill live‑reload.
Note: This project renders results in the DOM (via the
#resultselement), so runningnode main.jsin a terminal won’t work becausedocumentis not available in Node.
In main.js, scroll to the bottom where the sample cards are created and tweak the input values:
- Update the example strings passed to
reverseString,countCharacters, andcapitalizeWords. - Change the
numbersarray to test different datasets forfindMaximum,findMinimum,sumOfArray, andfilterArray. - Adjust the numbers for
factorial,isPrime, and the number of terms forfibonacciSequence.
You can also reuse the functions elsewhere—each is a plain, pure function.
- If you need to share a link with your instructor:
- Create a GitHub repository, add these three files, and push.
- Enable GitHub Pages on the repo (Settings → Pages) and pick the main branch.
- Share the GitHub Pages URL or the repository link.
- Alternatively, compress the folder as a
.zipand submit/upload per instructions.
- Code is written in plain ES5/ES6 JavaScript, no external dependencies.
- Styling is minimal and responsive; tweak
style.cssas you like. - Functions are documented inline with clear names for readability.