"use strict"; //! {"require": ["ui"]} terminal.setEcho(false); terminal.setTitle("Programming Contest Test"); let kProblem = { description: "Write a function foo that returns a number.", tests: [ [1, 1], [2, 2], [4, 4], ], default: `// Problem 1 // ${core.user.name} // ${new Date()} function foo() { print("hi cory"); return 0; } foo();`, }; function back() { terminal.split([{name: "terminal"}]); if (gEditEvent) { gEditEvent.back(); } } function runScript(script, input) { var results = {}; try { var output = []; function print() { for (var i in arguments) { output.push(arguments[i].toString()); } output.push("\n"); } results.results = eval(script || ""); results.output = output.join(""); } catch (error) { results.error = error; } return results; } function sendResults(document) { var results = runScript(document); var message = `${kProblem.description} Return value: ${results.results} Output: ${results.output} `; if (results.error) { message += `Error: ${results.error}`; } terminal.postMessageToIframe("iframe", { results: message }); } function loadScript() { return database.get(core.user.name).then(function(script) { return script || kProblem.default; }).catch(function(error) { return kProblem.default; }); } core.register("onWindowMessage", function(event) { if (event.message.ready) { loadScript().then(function(script) { terminal.postMessageToIframe("iframe", {contents: script}); sendResults(script); }); } else if (event.message.contents) { database.set(core.user.name, event.message.contents).then(function() { sendResults(event.message.contents); }); } }); //if (!core.user.credentials.permissions || !core.user.credentials.permissions.authenticated) { // terminal.print("Please authenticate."); //} else { showEditor(); //} function showEditor() { terminal.split([{name: "terminal", type: "vertical"}]); terminal.clear(); terminal.print({iframe: `