User Access Level
Programming Basics · JavaScript
TASK
Problem
Given role `guest`, `user`, `moderator`, or `admin`, print access level 0,1,2,3.
EXAMPLE
Example
moderator
2
LIMITS
Constraints
role is always valid
LEARN
Theory for this problem
+
### User Access Level
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.', 'Before printing, output only the computed result and do not add explanatory text that is absent from the required format.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let r = input;
if ((r) === ("guest")) {
console.log(0);
} else {
if ((r) === ("user")) {
console.log(1);
} else {
if ((r) === ("moderator")) {
console.log(2);
} else {
console.log(3);
}
}
}