Q: Changing letters in sentence? So my code has to change letters in "Eva has a cat" in javascript with jquery but i need to choose which letters will be changed for ex all a->t but i have something wrong in my code can you please help me?
I thought that mb my link to jq was wrong so i put in a link to google's jq                  but it doesn't work either
 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <form action="">

        <input type="text"id="p1">
        <input type="text"id="p2">
        <input type="button"value="Click me"id="g">
    </form>
    <div></div>

    <script>var p1;
            var p2;
            var zdj;
        var div=document.querySelector('div');
    $('#g').on('click',function(e){e.preventDefault();
        var p1=document.querySelector('#p1');
        var p2=document.querySelector('#p2');
        var zdj="Eva has a cat";
        for(let i=0;i<zdj.length;i++){
            if(zdj.charAt(i)===p1.values()){zdj.charAt(i)=p2.values()}
        }
        div.innerText=zdj;
    })

    </script>
</body>
</html>   


A: It seems from your example that you are not really using jQuery.
Also, it won't work to attribute a value to the result of charAt().
The easiest way would be to use the jQuery $, and to use the method String.prototype.replace, such as:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <form action="">

        <input type="text"id="p1">
        <input type="text"id="p2">
        <input type="button"value="Click me"id="g">
    </form>
    <div></div>

    <script>
        var p1;
        var p2;
        var zdj;
        // here you need to select the values using JQuery, not document.querySelector
        var div=$('div');

        $('#g').on('click', function(e){
            e.preventDefault();

            var p1=$('#p1');
            var p2=$('#p2');
            var zdj="Eva has a cat";

            // Now you can create a regular expression from the value of p1.
            // That value is retrieved using val(), not values()
            var expression = new RegExp(p1.val(), "g");

            // then you simply call string.replace passing that value
            zdj = zdj.replace(expression, p2.val());

            div.text(zdj);
        });
    </script>
</body>
</html>   

