Skip to content

Commit

Permalink
added Cookies to result page
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewsamuel95 authored Nov 30, 2016
1 parent 8bfd150 commit 4efacd4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
22 changes: 17 additions & 5 deletions DealorNoDeal.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function myFunction(buttonP){
if (typeof x != 'undefined'){
if(cases[x-1]!=0)
document.getElementById("case").innerHTML =
"That case was valued at: $"+cases[x-1];
"That case was valued at: $"+cases[x-1].toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
cases[x-1]=0;
}

Expand All @@ -64,11 +64,17 @@ function myFunction(buttonP){
turns=6-gamesPlayed;
if(gamesPlayed>6)
turns=1;
document.getElementById("message").innerHTML = "$"+average.toFixed(2);

document.getElementById("message").innerHTML
//money format with commas found online
= "Offer: $"+average.toFixed(2).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
//window.alert("$"+average.toFixed(2));

//if they select deal take them to new page
document.getElementById("Deal").href = "http://www.google.com/";
document.getElementById("Deal").href = "theResult.html";

//set cookie
setCookie("average",average,1);
}
else {

Expand All @@ -88,8 +94,8 @@ function myFunction(buttonP){
result.sort(function(a, b){return a-b})
var theAnswer="";
for(var p=1;p<result.length+1;p++){
theAnswer+=" $"+result[p-1];
if(p%2==0)
theAnswer+=" $"+result[p-1].toFixed(0).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
if(p%3==0)
theAnswer+="<div>";

}
Expand All @@ -100,6 +106,12 @@ function myFunction(buttonP){
function theTurns() {
turns--;
}

function calculateResult(){
var theAverage= getCookie("average");
document.getElementById("sub").innerHTML = theAverage;
}

//courtesy of w3schools, from: http://www.w3schools.com/js/js_cookies.asp
function setCookie(cname, cvalue, exdays) {
var d = new Date();
Expand Down
16 changes: 16 additions & 0 deletions theResult.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<!-- Matthew Samuel -->
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="DealorNoDeal.css" />
<title>Deal or No Deal Result</title>
<script type="text/javascript" src="DealorNoDeal.js"></script>
</head>
<body lang="en-US" onload="calculateResult()">
<h1>
Deal or No Deal Result
</h1>
<h2 id=sub> final result</h2>
</body>
</html>

0 comments on commit 4efacd4

Please sign in to comment.