NodeJS és böngészőben futó JavaScript tesztelésére.
function calcArea(base, height) { return 0.5 * base * height; } export {calcArea}
{ "type": "module" }
import { expect } from 'chai'; import { calcArea } from '../src/triangle.js'; describe('A calcArea() függvény tesztje', function() { it('Ha a bemenet 30, 35, eredmény 525', function() { const base = 30; const height = 35; const area = calcArea(base, height); expect(area).to.equal(525); }); });
import { calcArea } from "./triangle.js"; function handleSubmit(event) { event.preventDefault(); const base = parseFloat(document.getElementById('base').value); const height = parseFloat(document.getElementById('height').value); const area = calcArea(base, height); document.getElementById('result').value = area; } document.getElementById('triangleForm').addEventListener('submit', handleSubmit);
<!DOCTYPE html> <html lang="hu"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Háromszög</title> </head> <body> <h1>Háromszög területszámítás</h1> <form id="triangleForm"> <label for="base">Alap</label> <input type="number" id="base" name="base" required value="30"> <br> <label for="height">Magasság</label> <input type="number" id="height" name="height" required value="35"> <br> <button type="submit">Számít</button> </form> <br> <label for="result">Terület</label> <input type="text" id="result" name="result" readonly> <script type="module" src="app.js"></script> </body> </html>