Reply To: DashedSentence in a PennController trial

PennController for IBEX Forums FAQ / Tips DashedSentence in a PennController trial Reply To: DashedSentence in a PennController trial

#5439
Jeremy
Keymaster

Hello Max,

The special characters in forums posts mess with some characters in javascript code, it’s really frustrating I must say. I tried editing your last message so it displays the javascript code correctly.

In order to make all words appear the same length when masked, would you be willing to use the longest-word’s length for all of them? Because that would make life easier:

showWord = (s,i,m) => '<p>'+s.map( (w,n) =>
            `<span style='display: inline-block; text-align: center; width: ${m}ch; 
            ${(i===n?'':'border-bottom:solid 1px black;\'><span style=\'visibility:hidden;\'')}'>
            ${w}${(i===n?"":'</span>')}</span>`
        ).join(' ')+'</p>'
        
dashed = (name, sentence) => {
    let words = sentence.split(' '), maxwidth = 0;
    words.map(w=>maxwidth=Math.max(w.length,maxwidth));
    return [
        [newText(name, showWord(words,null,maxwidth)).print()], 
        ...words.map( (w,i) => [newKey(`${name}-${i}-${w}`," ").log().wait() , getText(name).text(showWord(words,i,maxwidth))] ),
        [newKey(`${name}-last`," ").log().wait()]
    ].flat(1);
}

newTrial(
    ...dashed("test","A local man is in a great amount of debt due to gambling.")
    ,
    newButton("Finish").print().wait()
)

Jeremy