Staff who can help me, I am a beginner in javascript,

-2

I wanted to make the number of clicks stored in the localStorage, and when I returned the number of clicks I would continue where I left off. I have tried doing so, but in alert only shows NaN :

<!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.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script></head><body><scripttype="text/javascript">
        var p = document.createElement("p");
        document.body.appendChild(p);

    $(document).ready(function(){

         var cout = localStorage.getItem('cout') || 0;

            $("#btnCount").click(function(){
                cout = parseInt(cout)+1;
                $('p').html(cout);
                alert(cout);
                localStorage.setItem('cout',cout);
            });         
    });    
    </script>
    <button type="button" id="btnCount">Click me</button>
</body>
</html>
    
asked by anonymous 08.11.2018 / 23:49

1 answer

0
   <script type="text/javascript">
        var p = document.createElement("p");
        p.setAttribute('id','num');
        document.body.appendChild(p);

    $(document).ready(function(){


        cout = localStorage.getItem('cout');
        cout = parseInt(cout) || 0; 

            $("#btnCount").click(function(){
                cout = cout+1;
                $('p').html(cout);
                // alert(cout);
                localStorage.setItem('cout',cout);
            });         
    }); 
    
09.11.2018 / 00:49