I was learning 去哪儿网-2017笔试题 and programing. In my program, I want to use readline()
function to read a single line from input from stdin
. I know that readline()
function belongs to JavaScript Shell according to MDN. But the function is not defined when I run the code in my browser.
var line;
while (line = read_line()) {
while (line.indexOf(" ") != -1) {
line = line.replace(" ", "");
}
if (line.length <= 6) {
print(line);
} else if (line.length > 6 && line.length <= 14) {
var line1 = line.substring(0, 6);
var line2 = line.substring(6);
print(line1 + " " + line2);
} else if (line.length > 14 && line.length <= 18) {
var line1 = line.substring(0, 6);
var line2 = line.substring(6, 14);
var line3 = line.substring(14);
print(line1 + " " + line2 + " " + line3);
}
}
If I want to run the code in my browser. What should I do?
Thank you very much.