-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimal_example.html
75 lines (60 loc) · 2.63 KB
/
minimal_example.html
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Minimal External Integration Example</title>
</head>
<body>
<div id="activity-container">
<p>Solve for x: 2x + 3 = 7</p>
<label for="answer">Your answer for x:</label>
<input type="text" id="answer" name="answer">
<button id="answer-btn" onclick="checkAnswer()">Answer</button>
<p id="feedback"></p>
<button id="submit-btn" onclick="submit()" style="display:none">Submit</button>
</div>
<script>
// Get URL parameters
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
let url_launch_token = urlParams.get('launch_token'); // Single-use launch token
const url_pid = urlParams.get('anonymous_id') // Participant ID
// If there is no launch_token provided, assume that this is a preview
if (url_launch_token == "" || url_launch_token == null || url_launch_token == undefined) {
url_launch_token = "00000000-0000-4000-B000-000000000000"; // reserved preview token
}
// Variable for the student's score
let score = 0;
// Container for responses
let responses = [];
function checkAnswer() {
// Get timestamp
var timestamp = Date.now();
// Correct answer
const correctAnswer = 2; // (2x + 3 = 7, x = 2)
// Get the user's answer from the input field
const userAnswer = document.getElementById("answer").value;
// Evaluate answer correctness
var correctness = parseFloat(userAnswer) === correctAnswer;
if (correctness) score += 1;
// Push the response
responses.push({
pid: url_pid,
question: "2x + 3 = 7",
correctAnswer: correctAnswer,
response: userAnswer,
correctness: correctness,
datetime: timestamp
});
// Display feedback and enable submit button
const feedback = document.getElementById("feedback");
feedback.textContent = JSON.stringify(responses); // save this
document.getElementById("answer-btn").disabled = true;
document.getElementById("submit-btn").style.display = 'inline-block';
}
function submit() {
window.location.href = `https://app.terracotta.education/integrations?launch_token=${url_launch_token}&score=${score}`
}
</script>
</body>