// Note: We keep the data and the states in this component class BasicStopExplain extends React.Component { constructor(props) { super(props); this.state = { // Check whether all nodes are clicked isClicked: [ true, true, true, true, true, true, true, true, true, true, true, true, true, true, true ], // Save continuation decision in percent continuation: [ 100, 100, 100, 0, -100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, // 1, 1, 1, 1, 1, 1, 1 // 1, 1, 1, 1, 1, 1, 1, 1 ], pdStopDecision : { "choice_4_0" : "Continue", "choice_4_1" : "Stop" }, stopPath: [100], // Save stop along the path, necessary for bonus ball // Save outcome path drawn: [0], currentRound: 0, currentNode: -1, // Keep track of currently clicked node imagePath: '/static/img/coin_questionmark.png', imagePathGuess: '/static/img/coin.png', winningSide: "", nextCoin: false, szenario: 1, paths: { "1": [0,1,3,7, 11, 17], // Path for szenario 1 "2": [0,1,4, 7, 12, 18], // Path for szenario 2 "3": [0,2,4, 7, 12, 18] // Path for szenario 3 }, showRepetitions: true, startAnew: false, showPDChoice:false, }, this.simulateCoinToss = this.simulateCoinToss.bind(this); this.winningSideUpdate = this.winningSideUpdate.bind(this); this.startAnewBtn = this.startAnewBtn.bind(this); this.nextCoin = this.nextCoin.bind(this); this.radioClick = this.radioClick.bind(this); this.updatePDStop = this.updatePDStop.bind(this); } winningSideUpdate(chosenSide) { // Disable winning side buttons var ele = document.getElementsByName("winningSideInput"); for(var i=0;i this.simulateCoinToss(), 500 ); } simulateCoinToss(){ const {paths} = this.state; let {currentNode, szenario, drawn, currentRound, showRepetitions, stopPath, startAnew, showPDChoice} = this.state; if (!showRepetitions){ document.getElementById("repetitionExplain").classList.add("d-none") return; } currentRound = currentRound + 1; let relPaths = paths[szenario] drawn[currentRound] = relPaths[currentRound] stopPath[currentRound] = this.state.continuation[drawn[currentRound]] // Grey background for selection section document.getElementById("pickWinningSide").classList.remove("alert-warning"); document.getElementById("pickWinningSide").classList.add("alert-secondary"); // Disable winning side buttons var ele = document.getElementsByName("winningSideInput"); for(var i=0;iwhite. White balls instruct the computer to continue risk-taking.
Please resolve the next single risk. ` document.getElementById("explanationCol").scrollIntoViewIfNeeded({ block: "end", inline: "nearest", behaviour: "smooth", }) } else if (szenario == 1 && currentRound ==2) { // Black ball - szenario 1 end document.getElementById("currentNode").innerHTML = ` This ball is black. A black ball instructs the computer to stop risk-taking.
If this was the result of your bonus task, your bonus would be the accumulated earnings at this ball plus the endowment. Thus, the ball is colored gold and contains a "B" for bonus.
Please click "Start anew" to practice another path through the ball triangle. ` stopPath[currentRound] = "Stop" startAnew = true } else if (szenario == 2 && currentRound == 2) { // white-black-gradient ball reached from above document.getElementById("currentNode").innerHTML = ` This ball is white-black-gradient.
The path taken to the ball was "first up, then down", as highlighted. The computer follows the exemplary instruction for this path as shown on the right and continues risk-taking.
Please resolve the next single risk. ` showPDChoice = true; currentNode = drawn[currentRound] } else if (szenario == 2 && currentRound == 3){ document.getElementById("currentNode").innerHTML = ` This ball is white. ` showPDChoice = false; currentNode = -1; } else if (szenario == 2 && currentRound == 5) { document.getElementById("currentNode").innerHTML = ` This ball is black.
You are in the last column of the ball triangle and no more single risks can be taken.
If this was the result of your bonus task, your bonus would be the accumulated earnings at this ball plus the endowment.
Please click "Start anew" to practice another path through the ball triangle. ` document.getElementById("explanationCol").scrollIntoViewIfNeeded({ block: "end", inline: "nearest", behaviour: "smooth", }) stopPath[currentRound] = "Stop" startAnew = true } else if (szenario == 3 && currentRound == 2) { // white-black-gradient ball reached from above document.getElementById("currentNode").innerHTML = ` This ball is white-black-gradient.
The path taken to the ball was "first down, then up", as highlighted. The computer follows the exemplary instruction for this path as shown on the right and stops risk-taking.
If this was the result of your bonus task, your bonus would be the accumulated earnings at this ball plus the endowment.
` showPDChoice = true; currentNode = drawn[currentRound] stopPath[currentRound] = "Stop" // Repetition ends next showRepetitions = false this.props.simulationCompleted(); } else { // All other balls are white balls document.getElementById("currentNode").innerHTML = ` This ball is white. ` } this.setState({ currentNode: currentNode, drawn: drawn, currentRound: currentRound, szenario: szenario, showRepetitions : showRepetitions, stopPath: stopPath, startAnew: startAnew, showPDChoice: showPDChoice, }, () => { // Set color of row in PD choice panel // Must be done here because only rendered if showPDChoice == true if (szenario == 2 && currentRound == 2) { document.getElementById("choice_4_0_row").classList.add("bg-light") document.getElementById("choice_4_1_row").classList.remove("bg-light") // Disable radio buttons const radios = document .getElementById("pdInstructCol") .getElementsByClassName("largerRadio") for (let i=0; i < radios.length; i++) { radios[i].disabled = true; } // Remove close button const footer = document .getElementById("pdInstructCol") .getElementsByClassName("card-footer") footer[0].classList.add("d-none") } else if (szenario == 3 && currentRound == 2) { document.getElementById("choice_4_0_row").classList.remove("bg-light") document.getElementById("choice_4_1_row").classList.add("bg-light") // Disable radio buttons const radios = document .getElementById("pdInstructCol") .getElementsByClassName("largerRadio") for (let i=0; i < radios.length; i++) { radios[i].disabled = true; } // Remove close button const footer = document .getElementById("pdInstructCol") .getElementsByClassName("card-footer") footer[0].classList.add("d-none") } }) } nextCoin() { document.getElementById("pickWinningSide").classList.add("alert-warning"); document.getElementById("pickWinningSide").classList.remove("alert-secondary"); document.getElementById("coinTossWon").classList.add("d-none") document.getElementById("coinTossLost").classList.add("d-none") document.getElementById("moveUp").classList.add("d-none") document.getElementById("moveDown").classList.add("d-none") document.getElementById("placeholderFooter").classList.remove("d-none") var ele = document.getElementsByName("winningSideInput"); for(var i=0;iwhite. ` var ele = document.getElementsByName("winningSideInput"); for(var i=0;i { this.updatePDStop(clickedRadios); }, 200); } } updatePDStop(clickedRadios) { let {pdStopDecision} = this.state for (let i=0; i< clickedRadios.length; i++){ let thisRadio = clickedRadios[i]; let path = thisRadio.name let decision = thisRadio.value pdStopDecision[path] = decision } this.setState({pdStopDecision:pdStopDecision}) } render () { return ( <>
Coin toss: Win or lose?
Coin toss outcome The winning side
 
Heads Tails
this.winningSideUpdate("H")} className="largerRadio"/> this.winningSideUpdate("T")} className="largerRadio"/>
You won this single risk.
You lost this single risk.
The repeated risk
You moved up.
{ this.state.showRepetitions ? <> { (!this.state.startAnew) ?
:
} : <> }
You moved down.
{ this.state.showRepetitions ? <> { (!this.state.startAnew) ?
:
} : <> }
{/* Left column with textual description of current ball */}
{/* Right column showing path-dependent stopping decision */} { this.state.showPDChoice && }
) } }