123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <section class="container">
    <input id="userName" type="text" placeholder="Name" />
    <input id="skillLevel" type="text" placeholder="Skill" />
    <input id="totalDist" type="number" placeholder="Distance?" />
    <h1 class="swim-practice" id="title"></h1>

    <button class=button id="submit">
        Generate
    </button>


</section>
            
          
!
            
              
@import url(https://fonts.googleapis.com/css?family=Give+You+Glory|Walter+Turncoat|Shadows+Into+Light+Two|Reenie+Beanie|Limelight|Ewert|Rock+Salt|Nothing+You+Could+Do|Permanent+Marker|Kaushan+Script);

body {
    background: #FDF6E3;
}
.swim-practice {
    font-size: 3em;
    text-align: center;
    margin-top: 30px;
}
.container {
    margin: 0 auto;
    text-align: center;
    width: 650px;
    position: relative;
}

input[type="text"], input[type="number"] {
    background: #FDF6E3;
    width: 110px;
    padding: 10px;
    margin-top: 30px;
    border: none;
    border-bottom: solid 2px #c9c9c9;
    transition: border 0.3s;
    border-bottom: solid 2px #969696;
    font-family: "Permanent Marker";
    font-size: 18pt;
}

.button {
    background: #2AA198;
    font-family: 'Roboto';
    width: 180px;
    height: 35px;
    padding: 4px 0;
    display: block;
    position: absolute;
    left: 235px;
    top: 400px;
    margin: 0 auto;
    border-radius: 30px;
    line-height: 1.5em;
    font-size: 1.3em;
    text-align: center;
    text-transform: uppercase;
    color: #FFF;

}


            
          
!
            
              

$(document).ready(function() {
    //Only Numbers Code source:
    //http://stackoverflow.com/questions/16689588/jquery-cannot-retrieve-input-number-value
    function onlyNumbers(evt) {
        // SOME OPTIONS LIKE ENTER, BACKSPACE, HOME, END, ARROWS, ETC.
        var arrayExceptions = [8, 13, 16, 17, 18, 20, 27, 35, 36, 37,
            38, 39, 40, 45, 46, 144];
        if ((evt.keyCode < 48 || evt.keyCode > 57) &&
            (evt.keyCode < 96 || evt.keyCode > 106) && // NUMPAD
            $.inArray(evt.keyCode, arrayExceptions) === -1) {
            return false;
        }
    }

    $('#totalDist').on('keydown', onlyNumbers);


    //Do the magic
    //Original CodePen inspiration:  Beer Name Generater
    $(".button").click(function(getName) {
        var randomNumber = function (max, min) {
            return Math.floor(Math.random() * (max - min)) +
                min;
        };
        var //workoutType = ["Endurance", "Speed", "Form"],
            workoutType = ["Endurance"],

            pattern = [
                "Pyramid"
                //"Blocks", "Ladder", "Pyramid", "Rounds"
            ],

            /*
                endurancePatterns = [["Pyramid 3", 1, 2, 3],
             ["Pyramid 4", 1, 2, 3, 4],
                ["Pyramid 5", 1, 2, 3, 4, 5]],
*/
            //randomise = randomNumber(3, 0),

            randyType = randomNumber(workoutType.length, 0),

            randyPattern = randomNumber(pattern.length, 0),

            //randyEP = randomNumber(endurancePatterns.length, 0),

            randomWorkoutType = workoutType[randyType],

            randomPattern = pattern[randyPattern],

            //randomEndurancePattern = endurancePatterns[randyEP],

            fonts = ["'Nothing You Could Do'", "'Rock Salt'", "'Permanent Marker'",
                "'Kaushan Script'", "'Shadows Into Light Two'", "'Reenie Beanie'",
                "'Walter Turncoat'", "'Give You Glory'"
            ],
            name = document.getElementById('userName').value,
            totalDist = $("#totalDist"),
            repeatMin = 25,  //dynamically generated based on skill?
            repeatMax = 100, //dynamically generated based on skill?
            poolCourse = 25, //input or preference
            poolMeasure = ["Y", "M"],
            practiceSet="";


        if (name.length >= 1) {
            if (randomWorkoutType === "Endurance") {

                //  if repeat min=25, repeat max=100, distance = 500
                var baseDistance = 25, pyramidSteps = 0,
                    pyramidUp = false, repeatTop = false;
                //  expect pyramid 3 pattern
                //  6 x [25,50,75]
                //
                //  expect pyramid 4 pattern
                //  4 x [25,50,75,100]
                //
                //  expect pyramid 5 pattern
                //  2 x [25,50,75,100,125]
                //
                //  given repeat min & max, create min of X even steps bewteen them in increments * pool length


                if (randomPattern === "Pyramid") {
                    //  Pyramid Can be 3, 4 or 5 steps
                    pyramidSteps = Math.floor(Math.random()*3+3);

                    //  Pyramid can be up or down
                    //  (pyramidUp will be true (-1) or false (0)
                    pyramidUp = Math.floor(Math.random()*2-1);

                    //  Pyramid can repeat top or not
                    //  (pyramidUp will be true (-1) or false (0)
                    repeatTop = Math.floor(Math.random()*2-1);

                    //  Get total distnace based on pyramid type & base distance
                    if (repeatTop) {
                        var pyramidDistance = gaussSum(pyramidSteps) * baseDistance * 2;
                    }   else {
                        var pyramidDistance=  gaussSum(pyramidSteps) * baseDistance +
                            gaussSum(pyramidSteps-1)*baseDistance;
                    }

                    //How many rounds fit into requested set size?
                    var rounds = Math.floor(parseInt(totalDist.val()) / pyramidDistance);

                    //check to see if #rounds fit request
                    //alternatively check to see if setDistance <= requestDistance
                    if (rounds<1) {
                        //
                    }

                    // String output the actual set
                    practiceSet = pyramidSteps +" Step " + randomPattern  +
                                   "<br />" + outputPyramid(baseDistance, pyramidSteps, pyramidUp, repeatTop) +
                                    "<br /> Rounds: " + rounds +
                                    "<br /> Distance: " + pyramidDistance*rounds;

                    //  If Rounds > 6, request a 2nd pattern
                }  else {

                    //Logic for other patterns will go here
                    practiceSet = randomPattern;

                }

                function outputPyramid(base, steps, upDown, repeatTop){
                    var set = "", i=0, j=0;
                    for (i=1; i<=steps; i++) {
                         set += (i*base).toString() + "+";
                    }
                    if (repeatTop) {
                        set +=  (steps)*base.toString() + "+";
                    }
                    for (j=steps-1; j>=1; j--) {
                        set += (j*base).toString();
                        if (j!=1) {
                            set+= "+";
                        }
                    }

                    return set;

                }
                /*
                if (randomEndurancePattern[0] === "Pyramid 3") {
                    rounds = Math.floor(parseInt(totalDist.val()) / (6 * 25));
                    practiceSet = randomEndurancePattern[0] + "<br /> Rounds: " + rounds + "<br />";
                }  else if (randomEndurancePattern[0] === "Pyramid 4") {
                    rounds = Math.floor(parseInt(totalDist.val()) / (10 * 25));
                    practiceSet = randomEndurancePattern[0] + "<br /> Rounds: " + rounds + "<br />";
                }   else if (randomEndurancePattern[0] === "Pyramid 5") {
                    rounds = Math.floor(parseInt(totalDist.val()) / (15 * 25));
                    if (rounds<1) {
                        //
                    }
                    practiceSet = randomEndurancePattern[0] + "<br /> Rounds: " + rounds + "<br />";
                }
                */
                /*
                for (i = 1; i < randomEndurancePattern.length; i++) {
                    practiceSet = practiceSet + randomEndurancePattern[i].toString()
                    if (i < randomEndurancePattern.length - 1)
                        practiceSet = practiceSet + ",  ";
                }
                */

            } else if (randomWorkoutType === "Speed") {
                practiceSet = "Speed";

            } else {
                practiceSet = "Form"
            }



            document.getElementById("title").style.fontFamily =
                fonts[randomNumber(fonts.length, 0)];
            document.getElementById('title').innerHTML =
                practiceSet +  "</br>";  //randomEndurancePattern;
        } else {
            alert("Enter your name first!");
        }
        //  }
    });
});

/**
 * Created by suzanne on 2/10/15.
 */

/** by crisberrios @ FCC */

function fill (minSteps, maxSteps, stepSize, steps)
{
    var arr = [];
    var factor = (maxSteps - minSteps) / (steps - 1) ;
    arr[0] = stepSize * minSteps;
    arr[steps-1] = stepSize * maxSteps;
    for (var i = 1 ; i < steps -1 ; i++ ) {
        arr[i] = stepSize * Math.round(minSteps + i*factor);
    }
    console.log("Fill array: " + arr);
    return arr;
}
//arr = fill(1,10,50,5);



/** Trying to refactor my pyramid stuff**/
/**  http://betterexplained.com/articles/techniques-for-adding-the-numbers-1-to-100/ **/
/**  forumula to sum an numbers up to & including n **/
/**  n * (n+1) / 2 **/

function gaussSum (n) {
    return  (n*(n+1)/2);
    console.log("Sum of Numbers up to " + n + ": " + total);
}



function randomize (){
    /*
     if (randomise === 0) {
     practiceSet = randomWorkoutType + name;
     } else if (randomise === 1) {
     practiceSet = name + randomPattern;
     } else {
     practiceSet = randomWorkoutType + name +
     randomPattern;
     }
     */
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console