Skip to content

Nidhal06/JavaScript-Project-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript Functions Checkpoint

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.


Project structure

.
├─ 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

Functions implemented

String manipulation

  • 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.

Array utilities

  • 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.

Mathematical helpers

  • factorial(n) → number | undefined: n! for n ≥ 0 (undefined for negative n).
  • 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].

How to run

You only need a browser.

  1. Double‑click index.html to open it in your default browser.

    • You should see three sections (cards) with computed results.
  2. Optional (recommended): use VS Code + Live Server

    • Install the "Live Server" extension.
    • Right‑click index.html → "Open with Live Server".
    • Any edits to main.js or style.css will live‑reload.

Note: This project renders results in the DOM (via the #results element), so running node main.js in a terminal won’t work because document is not available in Node.


Try your own inputs

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, and capitalizeWords.
  • Change the numbers array to test different datasets for findMaximum, findMinimum, sumOfArray, and filterArray.
  • Adjust the numbers for factorial, isPrime, and the number of terms for fibonacciSequence.

You can also reuse the functions elsewhere—each is a plain, pure function.


Submission tips

  • 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 .zip and submit/upload per instructions.

Notes

  • Code is written in plain ES5/ES6 JavaScript, no external dependencies.
  • Styling is minimal and responsive; tweak style.css as you like.
  • Functions are documented inline with clear names for readability.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published