PROBLEM 18
Easy

Triangle Area

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#18

Given base `a` and height `h`, print triangle area.

EXAMPLE

Example

Input
10 6
Output
30.0

LIMITS

Constraints

a > 0; h > 0
📖
LEARN Theory for this problem
+

### Triangle Area

`if / else if / else` chooses a branch from boolean conditions. Comparisons such as `<`, `>=`, `===` and logical operators `&&`, `||`, `!` combine the exact rules that decide which output is valid.

💡
NEED HELP? Hints
+

['Translate every case from the statement into a boolean condition before writing branches.', 'Separate input parsing, result computation, and output into distinct steps so errors are easier to spot.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [a, h] = input.trim().split(/\s+/).filter(Boolean).map(Number);
let result = (a * h / 2);
console.log(Number.isInteger(result) ? result.toFixed(1) : result);