function getRound(r) {
if (r == 1) {return ''}
else {return 'Round ' + (r-1).toString()}
}
function getPart(r) {
if (r == 1) {return 'Part I'}
else {return 'Part II'}
}
function getPartRound(r) {return getPart(r) + ': ' + getRound(r)}
function getStage(r, stage) {return stage + ' Stage'}
function setPartAndRound(r, stage) {
let docPart = document.getElementById('part');
let docStage = document.getElementById('stage');
if (r == 1) {
docPart.innerHTML = getPart(r);
} else {
docPart.innerHTML = getPartRound(r);
docStage.innerHTML = stage;
}
}
function clickWrong(id) {
const answer = document.getElementById("answer");
const textAnswer = answer.textContent;
answer.style.display = "";
answer.style.color = "red";
answer.innerHTML = "Incorrect. " + textAnswer;
document.getElementById("comp_form").value = "False";
document.getElementById(id).style.background = "red";
document.getElementById("next_button").style.display = "";
if (id == "yes") {document.getElementById("no").disabled = true}
else {document.getElementById("yes").disabled = true};
}
function clickRight(id) {
const answer = document.getElementById("answer");
const textAnswer = answer.textContent;
answer.style.display = "";
answer.style.color = "green";
answer.innerHTML = "Correct. " + textAnswer;
document.getElementById("comp_form").value = "True";
document.getElementById(id).style.background = "green";
document.getElementById("next_button").style.display = "";
if (id == "yes") {document.getElementById("no").disabled = true}
else {document.getElementById("yes").disabled = true}
}
// New scripts for the PD experiment
// Create a shuffled sequence of numbers from 1 to n
function createRandomSequence(n) {
const numbers = Array.from({length: n}, (_, i) => i + 1);
for (let i = numbers.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[numbers[i], numbers[j]] = [numbers[j], numbers[i]];
}
return numbers
}
// Creates urn with 100 balls for the quiz
function makeTableWithSmallBalls(id, clickable=false, pickedBallNumber=0, pickedBallId='') {
const table = document.getElementById(id);
// Create a sequence of numbers assigned to balls
const numbers = createRandomSequence(100);
// Count balls
let ballNumber = 1;
for (let i = 1; i <= 10; i++) {
const row = document.createElement("tr");
for (let j = 1; j <= 10; j++) {
const buttonCell = document.createElement("td");
const button = document.createElement("button");
// Fix ids of balls, assign values from the random sequence generated before
button.className = 'buttonBallSmall';
button.value = numbers[ballNumber-1];
button.name = 'picked_ball_number';
button.id = 'ball' + ballNumber.toString();
// Check if the balls should be clickable on this page
if (clickable == false) {
button.style.pointerEvents = 'none';
// If yes, save the id of the clicked ball
} else {
button.addEventListener("click", () => {
document.getElementById('picked_ball_id').value = button.id;
})
}
ballNumber++;
buttonCell.appendChild(button);
row.appendChild(buttonCell);
}
table.appendChild(row);
}
// If showing a table after a ball was picked, hide the picked ball
if (pickedBallNumber > 0) {
const thisBall = document.getElementById(pickedBallId);
thisBall.style.backgroundColor = "white";
thisBall.style.borderColor = "white";
}
}
// Creates choice table for the quiz
function makeChoiceTable(id, nRows, bonus, inactive, minRow=0, checkZero=true) {
const table = document.getElementById(id);
// Add a table head
const tableHead = document.createElement('thead');
const rowHead = document.createElement('tr');
const headCellsText = [
'№',
'Option A
' +
'Win ' + bonus + ' if the number on the picked
' +
'ball is ≤ than the number on the line;
' +
'win 0 otherwise',
'',
'',
'Option B
' +
'Win ' + bonus + ' if the other
' +
'person chose action 2;
' +
'win 0 otherwise'
]
for (let i=0; i < headCellsText.length; i++) {
const newHeadCell = rowHead.insertCell();
newHeadCell.innerHTML = headCellsText[i];
newHeadCell.style.textAlign = "center";
}
table.appendChild(tableHead);
table.appendChild(rowHead);
// Add table body
const tableBody = document.createElement('tbody');
table.appendChild(tableBody);
for (let i = minRow; i <= nRows; i++) {
const newRow = tableBody.insertRow();
// Index of the question
const cellNumber = newRow.insertCell();
cellNumber.innerHTML = `${i}`;
// Option A description
const cellBetUrn = newRow.insertCell();
const n = i * 10;
cellBetUrn.innerHTML = `Bet on the number on the ball being ≤ ${n}`;
const alternative = `${n}`
// Two checkboxes
const sides = ['l', 'r'];
for (let s = 0; s <=1; s++) {
const cellCB = newRow.insertCell();
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.id = `box${i}` + sides[s];
checkbox.disabled = inactive;
cellCB.appendChild(checkbox);
}
// Only one checkbox out of two can be checked
for (let s = 0; s<=1; s++) {
const thisCheckbox = document.getElementById(`box${i}` + sides[s]);
const otherCheckbox = document.getElementById(`box${i}` + sides[1-s]);
thisCheckbox.addEventListener('click', () => {
if (thisCheckbox.checked) {
otherCheckbox.checked = false;
}
});
}
// Option B description
const cellBetPartner = newRow.insertCell();
cellBetPartner.innerHTML = 'Bet that the other person chose action 2';
}
// In the 0 question, Option B is checked
if (checkZero == true){
document.getElementById('box0r').checked = true;
}
}