Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
<head>
    <title>U.S. ELECTION MAP</title>
<script type="text/javascript" src="https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2017/11/map.js"></script>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,700|Montserrat:400,700' rel='stylesheet' type='text/css'>
    <link href="https://fonts.googleapis.com/css?family=Bitter" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="style.css">


</head>

<body onload="onLoad();">
<div class="page">
    <header>
        <h1>U.S. ELECTION MAP</h1>
    </header>

    <div class="map-container">

        <canvas id="map_canvas" width="800" height="550" style="position:relative;">
        </canvas>

        <table id='stateResults' style="position:absolute; bottom:10px; right:10px;">
            <theader>
                <tr>
                    <th>STATE NAME</th>
                    <th>Abbreviation</th>
                </tr>
            </theader>
            <tbody>
            <tr>
                <td class="name-1">NAME1</td>
                <td class="name-1">RESULTS1</td>
            </tr>
            <tr>
                <td class="name-2">NAME2</td>
                <td class="name-2">RESULTS2</td>
            </tr>
            <tr>
                <td class="winner">WINNER:</td>
                <td class="winner">WINNER NAME</td>
            </tr>
            </tbody>
        </table>

        <table id='countryResults' style="position:absolute; top:10px; left:10px;">
            <tbody>
            <tr>
                <td class="name-1">NAME1</td>
                <td class="name-1">RESULTS1</td>
                <td class="name-2">NAME2</td>
                <td class="name-2">RESULTS2</td>
                <th>WINNER</th>
                <th>Name</th>
            </tr>
            </tbody>
        </table>

    </div>
    <br clear="all">
    <footer>
        <p>&copy; Skillcrush 2016 <span>//</span> HTML5 Map Created By: <a href="http://dougx.net/map/usmap.html" target="_blank">DougX.net</a></p>
    </footer>

</div>

<!--
JavaScript files are added just before </body> so all HTML loads first.
This can make your page appear to load faster and helps avoid missing HTML errors.
 -->

<!-- map.js -->
<!-- custom js (uncomment when you've added your custom script.js file) -->
<!--<script type="text/javascript" src="script.js"></script>-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
  <script type="text/javascript" src="script.js"></script>
</body>
</html>

              
            
!

CSS

              
                .page {
  width: 80%;
  max-width: 960px;
  margin: 0 auto;
  text-align: left;
  background-color: #eee;
}

body {
  font: 16px/26px 'Open Sans', Helvetica, Arial, sans-serif;
  color: #454545;
  margin: 0px;
  padding: 0px;
  background-color: #eee;
}

header {
  padding: 0.75em 0;
  text-align: center;
  font-family: 'Montserrat', serif;
  font-size: 21px;
  text-shadow: 1px 1px #ccc;
}

.map-container {
  width:800px;
  margin: 0 auto;
  position:relative;
}

#stateResults {
  width: 25%;
  font: 12px/16px 'Open Sans', Helvetica, Arial, sans-serif;
  color: #454545;
}

#countryResults {
  width: 95%;
  font: 16px/28px 'Open Sans', Helvetica, Arial, sans-serif;
  color: #454545;
}
#stateResults, #countryResults {
  border-collapse: collapse;
  background-color: #f2f2f2;
  -webkit-box-shadow: 1px 1px 1px 1px rgba(204,204,204,0.5);
  -moz-box-shadow: 1px 1px 1px 1px rgba(204,204,204,0.5);
  box-shadow: 1px 1px 1px 1px rgba(204,204,204,0.5);
}

th, td {
  text-align: left;
  padding: 8px;
}
#stateResults th{
  background-color: #3b3b3b;
  color: white;
}
#countryResults th {
  background-color: #f16059;
  color: white;
}
.name-1 {
  background-color: rgb(132,17,11);
  color: white;
}
.name-2 {
  background-color: rgb(245, 141, 136);
  color: white;
}
.winner {
  background-color: #f16059;
  color: white;
}

footer p {
  font-family: "Montserrat", sans-serif;
  font-size: 12px;
  text-align: center;
  text-transform: uppercase;
}
footer span {
  color: #f16059;
  padding: 0 5px;
}

              
            
!

JS

              
                

var setStateResults = function(state)
{
    theStates[state].winner = null;
  
  if (candidate1.electionResults[state] > candidate2.electionResults[state]){
      theStates[state].winner = candidate1;
    } else if (candidate2.electionResults[state] > candidate1.electionResults[state]){
      theStates[state].winner = candidate2;
    }
  
  var stateWinner = theStates[state].winner;
if (stateWinner !== null) {
  theStates[state].rgbColor = stateWinner.partyColor;}
else {
    theStates[state].rgbColor = [11, 32, 57];}

  var stateInfoTable = document.getElementById("stateResults");
  var stateTableHeader = stateInfoTable.children[0].children[0];
  var stateTableBody   = stateInfoTable.children[1];
  
  var stateName = stateTableHeader.children[0];
  var stateAbbrev = stateTableHeader.children[1];
  
  var name1 = stateTableBody.children[0].children[0];
  var numVotes1 = stateTableBody.children[0].children[1];
  var name2 = stateTableBody.children[1].children[0];
  var numVotes2 = stateTableBody.children[1].children[1];
  var nameWinner = stateTableBody.children[2].children[1];
  var winnerTitleTD = stateTableBody.children[2].children[0];
  
  stateName.innerText = theStates[state].nameFull;
  stateAbbrev.innerText = theStates[state].nameAbbrev;

  name1.innerText= candidate1.name;
  name2.innerText = candidate2.name;
  numVotes1.innerText = candidate1.electionResults[state];
  numVotes2.innerText = candidate2.electionResults[state]
 
 if (theStates[state].winner === null){
  nameWinner.innerText = "It's a tie."
 } else {
   nameWinner.innerText = stateWinner.name;
 }

    console.log("***"); 
 
  $([stateName, stateAbbrev]).css('background-color', '#3388ff');
  $([name1, numVotes1]).css('background-color', candidate1.partyColor);
  $([name2, numVotes2]).css('background-color', candidate2.partyColor);
  
  if (theStates[state].winner === null){
  $([winnerTitleTD, nameWinner]).css('background-color', "#3b3b3b");
 } else {
  $([winnerTitleTD, nameWinner]).css('background-color', stateWinner.partyColor);
 }
  
};



var makePolitician = function(name, partyColor)
{

  var politician = {};
    politician.name = name;
    politician.electionResults = null;
    politician.totalVotes = 0;
    politician.partyColor = partyColor;
    politician.totalVotes = function()
    {
    this.totalVotes = 0;
 
    for (var i = 0; i < this.electionResults.length; i++)
    {
         this.totalVotes = this.totalVotes + this.electionResults[i];
         
    }
 };
    return politician;
};


var candidate1 = makePolitician("Erica Kane", [177,165,201]);
var candidate2 = makePolitician("Donna Clark", [242,129,67]);

var winner = function(){
    if (candidate1.totalVotes > candidate2.totaVotes){
      winner = candidate1;
    } else if (candidate1.totalVotes === candidate2.totalVotes){
       winner = tieVotes;
    } else {
      winner = candidate2;}
  
  
     return winner;
}


candidate1.electionResults = [4, 2, 4, 4, 22, 3, 3, 1, 2, 15, 8, 1, 3, 9, 0, 6, 1, 
                        5, 5, 1, 3, 7, 8, 1, 3, 3, 1, 3, 2, 2, 6, 2, 14, 0, 1, 
                        6, 7, 3, 7, 3, 6, 1, 3, 17, 3, 1, 2, 11, 2, 3, 1];

candidate2.electionResults = [5, 1, 7, 2, 33, 6, 4, 2, 1, 14, 8, 3, 1, 11, 11,
0, 5, 3, 3, 3, 7, 4, 8, 9, 3, 7, 2, 2, 4, 2, 8, 3, 15, 15, 2, 12, 0, 4,
13, 1, 3, 2 , 8, 21, 3, 2, 11, 1, 3, 7, 2]

console.log("original count: " + candidate1.electionResults.length);


//recount
candidate1.electionResults[9] = 1;
candidate2.electionResults[9] = 28;

candidate1.electionResults[4] = 17;
candidate2.electionResults[4] = 38;

candidate1.electionResults[43] = 11;
candidate2.electionResults[43] = 27;

console.log("recount count: " + candidate1.electionResults.length);


candidate1.totalVotes();
console.log(candidate1.name + " has " + candidate1.totalVotes + " total votes.");

candidate2.totalVotes();
console.log(candidate2.name + " has " + candidate2.totalVotes + " total votes.");

winner();
//declare victor
      console.log(winner.name + " wins with " + winner.totalVotes + " total votes!");

console.log(candidate1.partyColor, candidate2.partyColor)

countryResultsTable = document.getElementById("countryResults");
row = countryResultsTable.children[0].children[0]
row.children[0].innerText = candidate1.name;
row.children[1].innerText = candidate1.totalVotes;
row.children[2].innerText = candidate2.name;
row.children[3].innerText = candidate2.totalVotes;
row.children[4].innerText = winner.name;
row.children[5].innerText = winner.totalVotes;

  $([row.children[0], row.children[1]]).css('background-color', candidate1.partyColor);
  $([row.children[2], row.children[3]]).css('background-color', candidate2.partyColor);
  $([row.children[4], row.children[5]]).css('background-color', winner.partyColor);

        
              
            
!
999px

Console