...
In the HTML body of this activity (contained within <body>…</body> tags), there is a single math question: Solve for x: 2x + 3 = 7. The student is instructed to type their answer in a text input field labeled “answer.” Note that this activity also includes a an empty <p> tag that will be used for presenting feedback, and a hidden button to submit the activity.
...
Code Block | ||
---|---|---|
| ||
<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 = "0000000-0000-4000-a000B000-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> |
...