-
Notifications
You must be signed in to change notification settings - Fork 0
/
playapp.js
35 lines (30 loc) · 1.12 KB
/
playapp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function runCode() {
const code = document.getElementById('code').value;
const outputDiv = document.getElementById('output');
try {
// Assuming you're using eval for simplicity (not recommended in a real environment)
const result = eval(code);
outputDiv.innerHTML = `<p>Output:</p><pre>${result}</pre>`;
} catch (error) {
outputDiv.innerHTML = `<p>Error:</p><pre>${error}</pre>`;
}
}
function submitAnswer() {
const submittedCode = document.getElementById('code').value;
// Replace this with your server-side logic to check the submitted code against expected output
const expectedOutput = "Hello, World!";
const isCorrect = evaluateCode(submittedCode) === expectedOutput;
if (isCorrect) {
alert("Congratulations! Your answer is correct.");
} else {
alert("Sorry, your answer is incorrect. Please try again.");
}
}
function evaluateCode(code) {
// Replace this with your own code evaluation logic
try {
return eval(code);
} catch (error) {
return 'Error: ${error.message}';
}
}