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

              
                <h1>Golf Scorecard</h1>
<table class="table table-striped">
  <tr id="0">
    <th>Hole</th>
    <th>Par</th>
    <th>Score</th>
    <th>Over</th>
    <th>Actions</th>
  </tr>
  <tr id="1">
    <td>1</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="2">
    <td>2</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="3">
    <td>3</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="4">
    <td>4</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="5">
    <td>5</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="6">
    <td>6</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="7">
    <td>7</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="8">
    <td>8</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="9">
    <td>9</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="10">
    <td>10</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="11">
    <td>11</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="12">
    <td>12</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="13">
    <td>13</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="14">
    <td>14</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="15">
    <td>15</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="16">
    <td>16</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="17">
    <td>17</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="18">
    <td>18</td>
    <td>4</td>
    <td>-</td>
    <td>-</td>
    <td><button class="btn btn-success">+</button> <button class="btn btn-danger">-</button></td>
  </tr>
  <tr id="totals">
    <td id="allTotal">TOTALS</td>
    <td id="parTotal">-</td>
    <td id="scoreTotal">-</td>
    <td id="overTotal">-</td>
    <td id="NA"></td>
  </tr>
</table>

              
            
!

CSS

              
                /* center-align table columns */
th, td {text-align: center;} 
              
            
!

JS

              
                // assign the table row for hole 1 to a variable
var elem
  = document.getElementById("1");
// display the number of children (all td elements)
// console.log(elem.children.length);
// display the content of the + button, which is the first child of the fifth element
// console.log(elem.children[4].children[0]); 

// assign a function to the + button
elem.children[4].children[0].onclick 
  = function(){add1(elem);};
// assign a function to the - button
elem.children[4].children[1].onclick 
  = function(){subtract1(elem);};

// you don't have to define the function before you use it! 
function add1 (elem) {
  if(elem.children[2].innerHTML == "-") elem.children[2].innerHTML = "1";
  else {
    let currentScore = elem.children[2].innerHTML;
    currentScore = Number.parseInt(currentScore);
    elem.children[2].innerHTML = currentScore + 1;
  }
}

function subtract1 (elem) {
  if(elem.children[2].innerHTML == "-") elem.children[2].innerHTML = "-1";
  else {
    let currentScore = elem.children[2].innerHTML;
    currentScore = Number.parseInt(currentScore);
    elem.children[2].innerHTML = currentScore - 1;
  }
}

/* your mission: 

1. Make all the + buttons add 1 to the score of the hole. Do not allow the score to exceed double the par. 
2. Make all the - buttons subtract 1 from the score of the hole. Do not allow the score to be negative!
3. Make the "Over" column display the difference, score - par, of the hole.
4. Make a table row's background color yellow if and only if that table row has a nonzero score.
5. Make the HTML table row with id="totals" display appropriate totals. Totals should be computed only for holes that have yellow-highlighted nonzero scores. Like the yellow-highlighted table rows above, the "totals" table row background color must be yellow if and only if it has a nonzero score. 
6. Add to the Action column a new button, C, which clears the current score for a given hole, and re-sets the table row background color to default.
7. Replace HTML table row code with JavaScript code that appends table rows. That is, delete the HTML elements with ID's 1 through 18, and write a function that loops 18 times, appending the appropriate DOM elements with ID's 1 through 18.  
8. Add a "RESET" button which clears all user-entered data. Use addEventListener method to add functionality to the button. See: https://www.w3schools.com/js/js_htmldom_eventlistener.asp. 
9. Add an "ABOUT" button which displays the message, "Golf Scorecard 1.0. All rights reserved."  Use an arrow function to add the "ABOUT" button to the DOM. See: https://www.w3schools.com/Js/js_arrow_function.asp.
10. Add a "FONT" button which toggles the font size of the entire app, from/to smaller to/from larger.
*. Advanced (optional): put circles around scores that are birdies, and squares around scores that are bogeys!
*/

              
            
!
999px

Console