PROBLEM 95
Hard

Guess the Number

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#95

Given secret number `secret` and guess `guess`, print `CORRECT`, `TOO LOW`, or `TOO HIGH`.

EXAMPLE

Example

Input
42 30
Output
TOO LOW

LIMITS

Constraints

All numeric input values fit in JavaScript `Number`.
📖
LEARN Theory for this problem
+

### Guess the Number

JavaScript arithmetic works with numeric values stored in variables. A clear solution reads the needed values, computes the formula with `+`, `-`, `*`, `/` or `**`, and prints only the final result.

💡
NEED HELP? Hints
+

['Write the formula using named intermediate values if it contains more than one operation.', 'Mentally substitute at least one value for each branch and verify that exactly the intended branch runs.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [s, g] = input.trim().split(/\s+/).filter(Boolean).map(Number);
if ((g) === (s)) {
    console.log("CORRECT");
} else {
    if (g < s) {
        console.log("TOO LOW");
    } else {
        console.log("TOO HIGH");
    }
}