Created
August 14, 2017 14:41
-
-
Save erintherad/1b7f7b093b00a4ef2c7c884c8950b9ec to your computer and use it in GitHub Desktop.
What is wrong with this function?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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