Hi there,
I'm trying to make something that changes all 'hello's to 'goodbye's, and all 'dog's to 'cat's. Here's what I've got.
Code:
<script type="text/javascript">
var str="Hello there cat, and hi other dog. ";
document.write(str.replace(/Hello/g, "Goodbye"),(/dog/g, "cat"));
</script>
I want that above code to output "Goodbye there cat, and hi other cat.", but it outputs "Goodbye there cat, and hi other dog. cat"
Also this:
<script type="text/javascript">
var str="Hello there cat, and hi other dog. Hello also other dog!";
document.write(str.replace(/Hello/g, "Goodbye"),(/dog/g, "cat"));
</script>
Which should output "Goodbye there cat, and hi other cat. Goodbye also other cat!"
But it outputs "Goodbye there cat, and hi other dog. Goodbye also other dog!cat"
WHY DOES THIS NOT WORK?? I'm obviously not making it replace useless things like 'god' and 'cat', but other things. I made it simple so it's easier to understand.