[[oktatas:web:javascript|< JavaScript]] ====== Állapotok és kötések tárolása ====== * **Szerző:** Sallai András * Copyright (c) 2023, Sallai András * Szerkesztve: 2023, 2024 * Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]] * Web: https://szit.hu ===== Számláló =====
const doc = { app: document.querySelector("#app"), button: document.createElement("button") }; let state = { count: 0 }; window.addEventListener('load', () => { init(); }) function init() { render(); doc.button.addEventListener("click", () => updateState() ); doc.app.appendChild(doc.button); } function updateState() { state.count += 1 render(); } function render() { doc.button.innerText = `Count: ${state.count}`; } ===== Háromszög területszámítás ===== Document

Háromszög

const doc = { baseInput: document.querySelector("#baseInput"), heightInput: document.querySelector("#heightInput"), areaInput: document.querySelector("#areaInput"), calcButton: document.querySelector("#calcButton") } const state = { base: 0, height: 0, area: 0 } window.addEventListener('load', () => { init(); }) function init() { doc.calcButton.addEventListener("click", () => { startCalc(); }) } function startCalc() { state.base = doc.baseInput.value; state.height = doc.heightInput.value; state.area = calcArea(state.base, state.height); doc.areaInput.value = state.area; } function calcArea(base, height) { return base * height / 2; } ===== Lásd még ===== * https://github.com/oktat/exemployee_statejs