Skip to content

sarahfenton204/JavaScript_Chap_1_2_Receipt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛒 Simple Grocery Checkout Receipt

👩‍💻 Authors


📚 Table of Contents


📄 Project Overview

This project is a simple grocery checkout application built using HTML, CSS, and JavaScript.
The program collects user input for a grocery purchase, validates the input, calculates totals (including tax and discounts), and displays a formatted receipt using a JavaScript alert.

The project is based on the Chapter 1 email_list example and modified to meet the assignment requirements for Chapters 1 and 2.


🧰 Tech Stack

Technology Purpose
HTML Structure of the form
CSS Styling and layout
JavaScript Logic, validation, and calculations

🛠️ Development Tools

Tool Description
Web Storm Code editor
Web Browser Testing and execution
GitHub Version control and hosting

🧠 Core Concepts / New Concepts

  • Client-side input validation
  • Conditional (ternary) operators
  • Template literals for formatted output
  • Currency formatting using toFixed(2)
  • JavaScript constants (const)
  • Clean, readable function-based logic

✨ Features

  • User-friendly grocery input form
  • Real-time input validation with error messages
  • Automatic calculation of totals, tax, and discounts
  • Conditional discount application
  • Formatted receipt display using alert()
  • Clean and organized code structure

🧮 Business Rules & Calculations

Rule Value
Tax Rate 8.25%
Discount Rate 10% (if subtotal ≥ $50)

Calculations:

  • Subtotal = Unit Price × Quantity
  • Discount = Subtotal × 10% (if eligible)
  • Taxable Amount = Subtotal − Discount
  • Tax = Taxable Amount × 8.25%
  • Total = Taxable Amount + Tax
  • Change = Cash − Total

✔ All currency values are formatted to two decimal places.


🧪 Input Validation

  • Required text fields must not be empty
  • Numeric fields must:
    • Be valid numbers
    • Be positive values
  • Errors are displayed next to input fields using <span> elements
  • Receipt is only displayed when all inputs are valid

🖼️ Visual Aids

📌 Example Output

image

image

image

💡 Reflection: What I Learned

Through this project, I strengthened my understanding of JavaScript fundamentals, especially input validation and conditional logic. I learned how to structure functions for readability and maintainability, and how to handle user input safely before performing calculations.

I also gained experience formatting output for users and applying real-world business rules like tax and discounts. This project helped reinforce the importance of clean code and user-friendly design in web development.


⬆ Back to TOC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors