I am trying to make a simple game in browser without using any backend. Is there a way for me to store the highest score in the browser using only javascript or react?
            Asked
            
        
        
            Active
            
        
            Viewed 182 times
        
    -3
            
            
        - 
                    3You can localStorage or sessionStorage – brk Nov 17 '19 at 07:10
- 
                    can I do it both in react and javascript? Which would work better? – pau Nov 17 '19 at 07:13
- 
                    Javascript Indeed, It provide same thing as react but in less lines of code it can be done – Ahmed Ali Nov 17 '19 at 07:15
1 Answers
2
            
            
        Yes , of course . You can use localStorage , this will alow you to store any information in the browser and fetch it later.
Example :
let score = 0;
score = 50;
localStorage.setItem('currentScore', score);
// And if you want to get the score
let getCureentScore = localStorage.getItem('score');
// do something with getCurrentScore
Hope this could helps you :)
 
    
    
        Ahmed Ali
        
- 1,908
- 14
- 28
 
    
    
        Marin Terziyski
        
- 221
- 1
- 11
- 
                    thank you so much for your response. Do you know what could be easier/better? React / vanilla js? Thank you for your patience, I am new to this! – pau Nov 17 '19 at 07:15
- 
                    In react or js app you can use it like in the example above , but if you want to do something else , maybe in react they have some additional packages. – Marin Terziyski Nov 17 '19 at 07:21
