<!DOCTYPE html> |
Tells the browser this is an HTML5 document |
Browser uses modern HTML rules |
Every modern HTML page |
<div> |
A container for grouping elements |
Groups calculator, display, buttons, etc. |
Layouts, cards, sections, components |
<input> |
An HTML element that accepts/displays data |
User or JavaScript can change its value |
Forms, search boxes, login fields, calculators |
id |
A unique name given to an HTML element |
JavaScript/CSS can locate that specific element |
Connecting HTML with JavaScript |
class |
A reusable label for styling/grouping elements |
CSS can target multiple elements with the same class |
Styling buttons, cards, menus, etc. |
getElementById() |
Finds an HTML element using its ID |
document.getElementById("display") returns that element |
Connecting JavaScript to webpage elements |
const |
Creates a variable that cannot be reassigned |
const display = ... keeps the same element reference |
Values/references that shouldn't be reassigned |
function |
A reusable block of code |
Call it whenever you need that task |
Calculations, validation, API calls, UI actions |
| Function parameter |
Input given to a function |
appendToDisplay(value) receives different values |
Making one function handle many situations |
onclick |
A click event handler |
Runs JavaScript when the user clicks an element |
Buttons, menus, interactive UI |
| Event |
Something that happens in the browser |
Click, typing, submitting, hovering, etc. can trigger code |
Almost every interactive website |
appendToDisplay() |
Custom function that adds content to the display |
Receives a value and adds it to display.value |
Reusable actions in apps |
.value |
Gets/sets the value of an <input> |
display.value = "123" changes what's inside it |
Forms, search fields, calculators |
+= |
Adds something to the existing value |
value += "7" means value = value + "7" |
Building strings, counters, totals |
clearDisplay() |
Custom function that clears the calculator |
Sets display.value to an empty string |
Resetting forms, search fields, inputs |
slice() |
Extracts part of a string |
slice(0, -1) removes the last character |
Delete buttons, text processing, formatting |
calculateResult() |
Custom function that performs the calculation |
Reads the expression and produces the result |
Reusable calculation/business logic |
eval() |
Evaluates a string as JavaScript code |
eval("10+20") returns 30 |
Generally avoid in production; useful for understanding the demo |
try...catch |
Handles errors without crashing the script |
try attempts code; catch handles an error |
API calls, parsing, file operations, error handling |
if...else |
Makes decisions based on conditions |
If condition is true, one block runs; otherwise another |
Validation, permissions, business rules |
document |
Represents the current webpage/HTML document |
Gives JavaScript access to the DOM |
DOM manipulation throughout web apps |
innerText |
Reads/changes visible text inside an element |
element.innerText = "Hello" changes displayed text |
Updating headings, messages, notifications |
display: grid |
CSS layout system |
Arranges buttons into rows and columns |
Dashboards, galleries, forms, card layouts |
grid-template-columns |
Defines grid columns |
repeat(4, 1fr) creates 4 equal columns |
Responsive layouts |
flex |
CSS layout system |
Helps align and position elements |
Navigation bars, centering, page layouts |
100vh |
100% of the browser viewport height |
Makes an element as tall as the visible screen |
Full-screen sections |
border-radius |
Rounds element corners |
50% can make a button circular |
Buttons, cards, profile images |
font-size |
Controls text size |
font-size: 24px makes text larger |
Typography/UI design |
cursor: pointer |
Changes cursor when hovering |
Indicates an element is clickable |
Buttons and interactive UI |