I'm trying to pass two arguments in a function that has String.prototype.slice(), but the console keeps on returning this error:
Uncaught TypeError: Cannot read property 'slice' of undefined".
Aren't the arguments supposed to be passed?
const testText = '<p style='color: red;'>This is a test</p>'
const testParagraph = document.getElementById('test')
const message = (paragraph, originText) => {
let i = 0,
text, isTag
const speed = 50
text = originText.slice(0, ++i)
if (text === originText) return
paragraph.innerHTML = text
const char = text.slice(-1)
if (char === '<') isTag = true
if (char === '>') isTag = false
if (isTag) return message()
setTimeout(message, speed)
}
message(testParagraph, testText)
<div id="test"></div>
const testText = '<p style='color: red;'>This is a test</p>'