Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <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; <a href="https://adrianne.dev" target="_blank">Adrianne P.</a> <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 -->
<script type="text/javascript" src="https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2017/11/map.js"></script>
<!-- custom js (uncomment when you've added your custom script.js file) -->
<script type="text/javascript" src="script.js"></script>

</body>

              
            
!

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 makePolitician = function(name, partyColor) {

    var politician = {}; // blank object
      
      politician.partyColor = partyColor; // candidate's party color here
      
      politician.name = name; // candidate's name here
      politician.electionResults = null;
      politician.totalVotes = 0;
        
      politician.tallyTotalVotes = function() {
        this.totalVotes = 0;
        
        for(var i = 0; i < this.electionResults.length; i++) {
          this.totalVotes = this.totalVotes + this.electionResults[i];
          
        }
      }
    
      return politician;
    
  };
  
  var yona = makePolitician("Sho Yonashiro", [132, 17, 11]);
  var ren = makePolitician("Ren Kawashiri", [245, 141, 136]);
  
  console.log("Sho's color is " + yona.partyColor);
  console.log("Ren's color is " + ren.partyColor);
  
  yona.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];
  
  ren.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];
  
  // Florida recount
  yona.electionResults[9] = 1;
  ren.electionResults[9] = 28;
  
  // California recount
  yona.electionResults[4] = 17;
  ren.electionResults[4] = 38;
  
  // Texas recount
  yona.electionResults[43] = 11;
  ren.electionResults[43] = 27;
  
  console.log(yona.electionResults);
  console.log(ren.electionResults);
  
  // State Results
  var setStateResults = function(state) {
    var stateInfo = document.getElementById('stateResults');
    var header = stateInfo.children[0];
    var body = stateInfo.children[1];
    var stateName = header.children[0].children[0];
    var abbrev = header.children[0].children[1];
    var candidate1Name = body.children[0].children[0];
    var candidate2Name = body.children[1].children[0];
    var can1Results = body.children[0].children[1];
    var can2Results = body.children[1].children[1];
    var winnersName = body.children[2].children[1];
    
      theStates[state].winner = null;
    
      if (yona.electionResults[state] > ren.electionResults[state]) {
        theStates[state].winner = yona;
      } else if (yona.electionResults[state] < ren.electionResults[state]) {
        theStates[state].winner = ren;
      }
    
    // State Colors
    var stateWinner = theStates[state].winner;
  
      if (stateWinner !== null) {
        theStates[state].rgbColor = stateWinner.partyColor;
      } else {
        theStates[state].rgbColor = [11, 32, 57];
      }
    
    // Per state results
    stateName.innerText = theStates[state].nameFull;
    abbrev.innerText = "(" + theStates[state].nameAbbrev + ")";
  
    candidate1Name.innerText = yona.name;
    candidate2Name.innerText = ren.name;
  
    can1Results.innerText = yona.electionResults[state];
    can2Results.innerText = ren.electionResults[state];
  
    if (theStates[state].winner === null) {
      winnersName.innerText = "DRAW";
    } else {
      winnersName.innerText = theStates[state].winner.name;
      }
    };
  
  
  // Overall country results
  yona.tallyTotalVotes();
  ren.tallyTotalVotes();
  
  console.log(yona.totalVotes);
  console.log(ren.totalVotes);
  
  var winner = "???";
  
    if (yona.totalVotes > ren.totalVotes) {
      winner = yona.name;
    } else if (yona.totalVotes < ren.totalVotes) {
      winner = ren.name;
    } else {
    winner = "DRAW!";
    }
  
  console.log("AND THE WINNER IS " + winner + "!!!");
  
  var countryInfo = document.getElementById('countryResults');
  var row = countryInfo.children[0].children[0];
  
  row.children[0].innerText = yona.name;
  row.children[1].innerText = yona.totalVotes;
  row.children[2].innerText = ren.name;
  row.children[3].innerText = ren.totalVotes;
  row.children[5].innerText = winner;
    
              
            
!
999px

Console