Hong-Phuc Bui
2026-10-24 35c96453b34ceca79e45cc39647f851653ee8f87
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const convertRatioInNumber = (r) => {
    const fraction = r.split(":");
    return Number.parseInt(fraction[0]) / Number.parseInt(fraction[1]);
}
 
const calDimension = (d, r) => {
    const h = d/(Math.sqrt(r**2 + 1));
    const b = r * h;
    return [b, h];
}
 
document.getElementById("ok").addEventListener("click", () => {
    const diagonal = document.getElementById("diagonal").value;
    const ratio = document.getElementById("ratio").value;
    //console.log({diagonal, ratio});
    const r = convertRatioInNumber(ratio);
    const d = Number.parseInt(diagonal);
    const result = calDimension(d, r);
    const output = document.getElementById("output");
    output.textContent = `${result[0].toFixed(2)} x ${result[1].toFixed(2)}`;
});