Listing 19.02 - Replacing one string with another - Tasks 2 & 3
- Declare a title variable and assign it a value.
- Use before.replace to replace the Replacing one string with another placeholder with the value of the title variable, rather than with a string literal.
var before = "<h3>Replacing one string with another</h3>";
var title = "Fitness App v1.0 Live!";
var after = before.replace("Replacing one string with another", title);
console.log(before);
console.log(after);
Listing 19.02 - Replacing one string with another - Tasks 4 & 5
- Include a second placeholder in the original string.
- Use the replace method to fill both your placeholder and Replacing one string with another with a value.
var before = "<h3>Replacing one string with another</h3><p></p>";
var title = "Fitness App v1.0 Live!";
var msg = "Finally, the app is available...";
var after = before.replace("Replacing one string with another", title);
after = after.replace("", msg);
console.log(before);
console.log(after);