0

Js change

So if you wanted to add something to a variable when user writes the letter/word in a function. Would you do this? var a = 0; var sentence = prompt("Write in something") if (sentence.includes("js")) { var fixed = sentence.replace("js",a++) }

9th Jul 2020, 2:30 PM
Sali65
Sali65 - avatar
1 Answer
+ 4
Firstly, you can't use that English quotation. You must use this " Secondly, you should use regex with global flag if you want to replace all Thirdly, you will replace js with 1 because it is one a++. If you want to count, use a callback function in replace. Here is a reference: https://code.sololearn.com/W1gwY8dptjRw/?ref=app
9th Jul 2020, 2:33 PM
Gordon
Gordon - avatar