Public
Edited
Dec 27, 2022
Insert cell
md`# Spelling bee`
Insert cell
Insert cell
viewof wordToMatch = {
const container = html`<div><input type=text placeholder="Mot à valider"></div>`
const input = container.querySelector("input")
input.addEventListener("focus", event => {
input.select()
})
input.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
mutable isNewGame = false
container.value = input.value
container.dispatchEvent(new CustomEvent("input"))
}
})
return container
}
Insert cell
message = {
if (mutable isNewGame) {
return "À toi de jouer!"
}
if (isValid) {
if (wasAlreadyFound) return "Déjà trouvé."
return "Bravo!"
} else return "Nope."
}
Insert cell
matches = {
const arr = mutable isNewGame ? [] : (this || []);
if (isValid && !arr.includes(wordToMatch)) {
arr.push(wordToMatch);
}
return arr;
}
Insert cell
viewof randomLetters = {
const form = html`<div><input type="submit" value="Nouvelles lettres"></div>`
form.addEventListener("click", event => {
event.preventDefault();
form.value = getRandomLetters()
mutable isNewGame = true
form.dispatchEvent(new CustomEvent("input"))
});
return form
}
Insert cell
numWords = validWords.length
Insert cell
html`<hr>`
Insert cell
html`
<style>
.hexes {
fill: silver;
stroke: white;
stroke-width: 8px;
width: 200px;
}
.hexes text {
fill: black;
stroke: none;
font-size: 72px;
font-family: Times;
}
.hexes .middle {
fill: gold;
}
</style>
`
Insert cell
mutable isNewGame = true
Insert cell
dictZip = FileAttachment("dico.zip").zip()
Insert cell
validWords = mots.filter(d => rgx.test(d)).filter(d => d.length > 3)
Insert cell
dict = dictZip.file("liste.de.mots.francais.frgut.txt").text()
Insert cell
mots = dict.split("\r\n")
Insert cell
getRandomLetters = function() {
const numVowels = ~~(Math.random() * 3 + 1)
const consonants = d3.shuffle("bcdfghjklmnpqrstvwxz".split("")).slice(0, 7 - numVowels)
const vowels = d3.shuffle("aeiouy".split("")).slice(0, numVowels)
return [...consonants, ...vowels]
}
Insert cell
Insert cell
wasAlreadyFound = wordsHistory.slice(0, -1).includes(wordToMatch)
Insert cell
wordsHistory = this ? (this.push(wordToMatch), this) : [wordToMatch]
Insert cell
isValid = validWords.includes(wordToMatch)
Insert cell
/*
to do
* prevent sets that have < than some words
* keep score
* see all words
* click on letters to form words
* center letter
* Hex layout
* prevent empty message on start
*/
Insert cell
import {formWithSumbit} from '@forresto/form-input-with-submit'
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more