0

hello everyone, tell me how to make it so that when the paint runs out, the remaining letters begin to be printed in black. For

class Marker { constructor(color, percentage ) { this.color = color; this.loaded = percentage; } setPrint(text) { let index; for (let letter of text) { index = text.indexOf(letter); if (letter != " ") { if (this.loaded) { this.loaded -= 25; } else break; } } let printedText = text.substr(0, index); printedText.style.color = this.color; let change = text.substr(index); let p = document.createElement('p'); document.body.appendChild(p); let c = document.querySelector('p'); c.innerHTML = printedText + change; } } let s = new Marker('blue', 50) s.setPrint('Hello')

26th May 2021, 10:33 AM
Тимур Завьялов
Тимур Завьялов - avatar
4 Respuestas
+ 2
Тимур Завьялов do your marker object print at maximum four characters before switching to black? (ie consume 25% of its load by char :o ?) anyway, here is a corrected / annotated working version of your code: https://code.sololearn.com/WDW7SUNK0baw/?ref=app (changed color from 'blue' to 'red' to better contrast with the default black ;P)
26th May 2021, 6:10 PM
visph
visph - avatar
+ 1
visph, thank you, your code is amazing
26th May 2021, 6:51 PM
Тимур Завьялов
Тимур Завьялов - avatar
0
For example, "He" is printed in blue, and "llo" is printed in black
26th May 2021, 10:34 AM
Тимур Завьялов
Тимур Завьялов - avatar
0
It works as I intended)
26th May 2021, 6:52 PM
Тимур Завьялов
Тимур Завьялов - avatar