-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.js
More file actions
41 lines (38 loc) · 966 Bytes
/
main.js
File metadata and controls
41 lines (38 loc) · 966 Bytes
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
36
37
38
39
40
41
// globals
const editor = ace.edit('editor');
$(function() {
// configure ace editor
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/python");
editor.setFontSize('14px');
});
// handle form submit
$('form').on('submit', (event) => {
event.preventDefault();
const answer = editor.getSession().getValue();
const payload = { answer: answer };
grade(payload);
});
// ajax request
function grade(payload) {
$.ajax({
method: 'POST',
url: 'https://c0rue3ifh4.execute-api.us-east-1.amazonaws.com/v1/execute',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify(payload)
})
.done((res) => {
let message = 'Incorrect. Please try again.';
if (res) {
message = 'Correct!';
}
$('.answer').html(message);
console.log(res);
console.log(message);
})
.catch((err) => {
$('.answer').html('Something went terribly wrong!');
console.log(err);
});
}