PROBLEM 64
Medium

Coordinate Quadrant

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#64

Given non-zero point coordinates `x`, `y`, print quadrant number 1..4.

EXAMPLE

Example

Input
-3 5
Output
2

LIMITS

Constraints

x ≠ 0; y ≠ 0
📖
LEARN Theory for this problem
+

### Coordinate Quadrant

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.', 'Match each input value type to the operation performed on it: JavaScript string and numeric behavior differ significantly.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [x, y] = input.trim().split(/\s+/).filter(Boolean).map(Number);
if ((x > 0) && (y > 0)) {
    console.log(1);
} else {
    if ((x < 0) && (y > 0)) {
        console.log(2);
    } else {
        if ((x < 0) && (y < 0)) {
            console.log(3);
        } else {
            console.log(4);
        }
    }
}