forked from cory/tildefriends
		
	Adding a number of work-in-progress packages. Some data structures built on top of the key-value store and an http client, among others.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3310 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		
							
								
								
									
										31
									
								
								packages/cory/await/await.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								packages/cory/await/await.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| "use strict"; | ||||
|  | ||||
| //! {"category": "tests"} | ||||
|  | ||||
| async function main() { | ||||
| 	terminal.print("Hi.  What's your name?"); | ||||
| 	let name = await terminal.readLine(); | ||||
| 	terminal.print("Hello, " + name + "."); | ||||
|  | ||||
| 	let number = Math.floor(Math.random() * 100); | ||||
| 	let guesses = 0; | ||||
| 	while (true) { | ||||
| 		terminal.print("Guess the number."); | ||||
| 		try { | ||||
| 			let guess = parseInt(await terminal.readLine()); | ||||
| 			guesses++; | ||||
| 			if (guess < number) { | ||||
| 				terminal.print("Too low."); | ||||
| 			} else if (guess > number) { | ||||
| 				terminal.print("Too high."); | ||||
| 			} else { | ||||
| 				terminal.print("You got it in " + guesses.toString() + " guesses!  It was " + number.toString() + ".  Good job, " + name + "."); | ||||
| 				break; | ||||
| 			} | ||||
| 		} catch (error) { | ||||
| 			terminal.print(error); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| main().catch(terminal.print); | ||||
		Reference in New Issue
	
	Block a user