window.onload = function(){

function setScore(){
	if(!localStorage.score){
		localStorage.score = 0;
	}
}
setScore();

function getScore(){
	if(localStorage.score){
		return(localStorage.score);
	}
}

function updateScore(newScore){
	if(localStorage.score){
		localStorage.score = newScore
	}
}

function showScore(){
    var scoreText = document.getElementById('scorediv');
	scoreText.innerHTML = "Current High Score is "+getScore();
}
showScore();

var scoreBtn = document.getElementById('scorebtn');
scoreBtn.addEventListener('click',getRandomScore,false);

function getRandomScore(){
	var randScoreText = document.getElementById('randomscorediv');
    randScoreText.style.visibility='visible';
	var randScore = Math.floor(Math.random()* 200000);
	var currentScore = Number(getScore());
	randScoreText.innerHTML = "Random Score is "+randScore;
	if(randScore > currentScore){
		alert("New High Score!!");
		updateScore(randScore);
		showScore();
	}
}
}