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(ng-app="quizApp", ng-controller="quizData")
   .container(ng-show="inProgress")
      .row(ng-show="!inRange")
         .col-sm-12
            .alert.alert-dismissible.alert-danger
               strong Your number is too high!
      .row
         .col-xs-8
             h1 I'm thinking of a number between 1 and {{limit}}
             h2 You have five guesses
             h2 Can you figure out what it is?
         .col-xs-4
            .panel.panel-info(ng-show="!guessStart")
               .panel-heading
                  h3.panel-title You can change the range here before you start!
               .panel-body
                  input(ng-model="limit")
            
      .row.guess.panel.panel-default(ng-show="possible")
         .col-sm-6
            input(ng-model="input", placeholder="Type your guess here!", type="number")
            br
            br
            a(ng-click="answer()").btn.btn-primary Guess
         .col-sm-6
            h3 Guesses: {{guess}}
            ul
               li(ng-repeat="guess in guesses") {{guess.text}}
         .col-sm-12.hints
            h3 Hints
            ol
               li(ng-repeat="hint in hints") {{hint.text}}
   
   .row(ng-show="!possible")
      .col-sm-12
         h2 Hey, you can't guess a number that doesn't exist! Make sure the range is more than 0!

   .container(ng-show="!inProgress").results
      div(ng-show="rightAnswer")
         h1 Congratulations, you guessed the number correctly!
         h2
            b Answer: {{number}}
         h3 You clearly kick a lot of ass! Or you got lucky. Either way, congrats!
      
      div(ng-show="wrongAnswer")
         h1 Sorry, you weren't able to guess the number!
         h2
            b Answer: {{number}}
         h3 No worries, you can always try again!
      
      a.btn.btn-default.btn-large.replay(href="javascript:history.go(0)") Play Again
            
              
            
!

CSS

              
                .guess {
   margin: 1em;
   padding: 2em 1em;
   min-height: 250px;
   
   input {
      width: 95%;
      margin-top: 2.5em;
   }
}

.hints {
   margin-top: 1.5em;
}

.results {
   text-align: center;
}

.panel-info {
   margin-top: 1em;
   
   input {
      width: 100%;
   }
}
              
            
!

JS

              
                var quizApp = angular.module('quizApp', []);

quizApp.controller("quizData", ["$scope", function($scope) {
   $scope.limit = 100;
   
   addToGuesses = function(text){
      $scope.guesses.push({
         'text': text
      })
   };
   
   addToHints = function(text){
      $scope.hints.push({
         'text': text
      })
   };
   
   highLow = function(numbertwo) {
      if ($scope.number < numbertwo) {
         return 'too high!'
      } else {
         return 'too low!'
      }
   };
   
   var q = {
      1: function(number) {
            var x = 3,
            y = 7,
            divider = Math.floor(Math.random()*((y-x)+1) + x);
            if (number%divider == 0) {
               return 'Your number is divisible by ' + divider
            } else {
               return 'Your number isn\'t divisible by ' + divider
            }
         },
      2: function(number) {
            var x = Math.round(($scope.limit * .35)),
            y = Math.round(($scope.limit * .65)),
            multiply = Math.floor(Math.random()*((y-x)+1) + x);
            if (number > multiply) {
               return 'Your number is greater than ' + multiply
            } else {
               return 'Your number is less than or equal to ' + multiply
            }   
         },
      3: function(number) {
            if (number%2 == 0) {
               return 'Your number is even'
            } else {
               return 'Your number is odd'
            }   
         },
      4: function(number) {
         var range = Math.round(($scope.limit / 10)),
             reach = Math.floor((Math.random()*range)),
             lower = number - reach,
             higher = number + (range - reach);
         
            if (lower < 0) {
               higher -= lower;
               lower = 0;
            }
         
            if (higher > $scope.limit) {
               lower -= (higher - $scope.limit)
               higher = $scope.limit;
            }
         
            return 'Your number is between ' + lower + ' and ' + higher;
         }
   };
   
   $scope.number = Math.floor((Math.random()*$scope.limit) + 1);
   $scope.input = '';
   $scope.guess = 0;
   $scope.inProgress = true;
   $scope.inRange = true;
   $scope.rightAnswer = false;
   $scope.wrongAnswer = false;
   $scope.guesses = [];
   $scope.hints = [];
   $scope.guessStart = false;
   $scope.possible = true;
   
   $scope.$watch('limit', function(){
      $scope.number = Math.floor((Math.random()*$scope.limit) + 1);
      
      if ($scope.limit < 1) {
         $scope.possible = false;
      } else {
         $scope.possible = true;
      }
   });
   
   $scope.answer = function() {
      if ( angular.isNumber($scope.input) ) {
         if ($scope.input > $scope.limit) {
            $scope.inRange = false;
         } else {
            $scope.inRange = true;
            
            if ($scope.input == $scope.number) {
               $scope.inProgress = false;
               $scope.rightAnswer = true;
            } else {
               $scope.guess++;
               // Removed "too high or low" hints
               // addToGuesses($scope.input + ' (' + highLow($scope.input) + ')');
               addToGuesses($scope.input);
               
               if ($scope.guess == 1) {
                  $scope.guessStart = true;
                }
               
               for (i = 0; i < 5; i++) { 
                   if ($scope.guess == i) {
                     addToHints(q[i]($scope.number));
                   }
               }
               
               if ($scope.guess == 5) {
                  $scope.inProgress = false;
                  $scope.wrongAnswer = true;
               }
               
               $scope.input = '';
            }
         }
      }
   };
}]);
              
            
!
999px

Console