JavaScript Program to Replace specified string value with another value

Write a java script that will replace following specified value with another value in a string.

string = “ i will fail” replace “fail” by “pass”

Source Code
    <title>Display number in words</title>
        var str = "I will fail";

        document.write("Original String : " + str);

        // strObj.replace(src, dest);
        document.write("<br><br>After replace string is : " + str.replace("fail", "pass"));
        var newStr = str