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)}`;
|
});
|