Published
Edited
Nov 4, 2019
Insert cell
md`# Rock Paper Scissors`
Insert cell
md`Rock Paper Scissors [says]....`
Insert cell
d3 = require("d3@5")
Insert cell
timer = d3.timer(() => mutable sec++);
Insert cell
mutable sec = 0;
Insert cell
userchoice =
html`<select>
<option value="rock">Rock</option>
<option value="paper">Paper</option>
<option value="scissors">Scissors</option>
</select>`
Insert cell
viewof button = {
const form = html`<form><button name=button>Shoot!`;
form.button.onclick = event => {
event.preventDefault(); // Don’t submit the form.
form.dispatchEvent(new CustomEvent("input"));
timer.stop();
};
return form;
}
Insert cell
computerchoice = {
button
return Math.ceil(Math.random()*3)
}
Insert cell
lastclick = {
button;
yield now;
}
Insert cell
{
button
if(computerchoice==1 && userchoice.value=='rock') {
return "it's a tie";
} else if(computerchoice==2 && userchoice.value=='rock') {
return "computer wins";
} else if(computerchoice==2 && userchoice.value=='rock') {
return "computer wins";
} else if(computerchoice==2 && userchoice.value=='rock') {
return "computer wins";
} else if(computerchoice==2 && userchoice.value=='rock') {
return "computer wins";
} else if(computerchoice==2 && userchoice.value=='rock') {
return "computer wins";
} else if(computerchoice==2 && userchoice.value=='rock') {
return "computer wins";
}
}

Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more