Skip to content

Instantly share code, notes, and snippets.

@erintherad
Created August 14, 2017 14:41
Show Gist options
  • Select an option

  • Save erintherad/1b7f7b093b00a4ef2c7c884c8950b9ec to your computer and use it in GitHub Desktop.

Select an option

Save erintherad/1b7f7b093b00a4ef2c7c884c8950b9ec to your computer and use it in GitHub Desktop.
What is wrong with this function?
let val = 0;
function runCommand(c) {
let words = c.split(' ');
let command = words[0];
let argument = words[words.length-1];
if(command == 'reset') {
val = 0;
} else if (command == "add") {
val = val + parseInt(argument);
} else if (command == "subtract") {
val = val - parseInt(argument);
} else {
return "quit";
}
console.log( "valus is: " + val);
return val;
}
var r = "";
do {
r = runCommand(prompt("next command:"));
} while (r !="quit");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment