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
<html>
<head>
    <title>Display number in words</title>
</head>
<body>
    <script>
        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
    </script>
</body>
</html>
Output