xxxxxxxxxx
47
// A2Z Fall 2024
// Daniel Shiffman
// https://github.com/Programming-from-A-to-Z/A2Z-F24
let wordInput;
let results;
function setup() {
noCanvas();
wordInput = select('#word');
// A button
let analyzeButton = select('#analyze')
analyzeButton.mousePressed(analyze);
let clearButton = select('#clearButton');
clearButton.mousePressed(clearAll);
}
function analyze() {
let p = createP('');
p.class('text');
let syllables = RiTa.syllables(wordInput.value());
// What's the count of syllables based on the slashes
let syllablesCount = syllables.split(/\//).length;
// Show
let syl = createDiv('Syllables: ' + syllables);
let count = createDiv('Count: ' + syllablesCount);
syl.parent(p);
count.parent(p);
}
// Go through and remove all the divs
function clearAll() {
let par = selectAll('.text');
for (let i = 0; i < par.length; i++) {
par[i].remove();
}
}