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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

HTML

            
              <div class="form">
	<header>
		<h1>WHICH PET FORM</h1>
		<h2>Please fill all the form bellow.</h2>  
	</header>
	<ul>
	  <li class="question">
	    <h3>Do you mind bathing your pet on a regular basis?</h3>
			<label class="choice">
			  <input type="radio" name="q1" value="dog" />
				<span>NOPE</span>
			</label>
			<label class="choice">
			  <input type="radio" name="q1" value="cat" />
				<span>YES, I SUCK AT BATHING</span>
			</label>
	  </li>
		<li class="question">
			<h3>Do you mind giving <b>lots</b> of attention to your pet?</h3>
			<label class="choice">
			  <input type="radio" name="q2" value="dog" />
				<span>NOPE</span>
			</label>
			<label class="choice">
			  <input type="radio" name="q2" value="cat" />
				<span>YES, I MY DAY IS KINDA FULL</span>
			</label>
	  </li>
		<li class="question">
	    <h3>Elegance of fussiness?</h3>
			<label class="choice">
			  <input type="radio" name="q3" value="cat" />
				<span>ELEGANCE</span>
			</label>
			<label class="choice">
			  <input type="radio" name="q3" value="dog" />
				<span>FUSS 4 EVAR!</span>
			</label>
	  </li>
		<li class="question">
	    <h3>Does barking is a problem for you?</h3>
			<label class="choice">
			  <input type="radio" name="q4" value="cat" />
				<span>YEAH :(</span>
			</label>
			<label class="choice">
			  <input type="radio" name="q4" value="dog" />
				<span>NOT ACTUALLY</span>
			</label>
	  </li>
		<li class="question">
	    <h3>Is affection a must for you?</h3>
			<label class="choice">
			  <input type="radio" name="q5" value="dog" />
				<span>MY PET MUST LOOOVE ME!</span>
			</label>
			<label class="choice">
			  <input type="radio" name="q5" value="cat" />
				<span>REGULAR WARMTH IS ENOUGHT</span>
			</label>
	  </li>
	</ul>
	<button class="button-submit" onclick="calcResults('.form')">SEE MY RESULT</button>

</div>
</div>

            
          
!

CSS

            
              @import url(https://fonts.googleapis.com/css?family=Lato:400,700,900);

@color-1st: #5f7796;
@color-2nd: #70b48b;
@color-3rd: #94a9c3;
@color-4th: #e9e9e9;

body{
	font-family:Lato, Helvetica, Arial, sans-serif;
	background:linear-gradient(#dfdbd7, #d7d3d3);
	color:#545454;
	margin:0;
	min-height:100vh;
}

.form{
	max-width:520px;
	background:#fff;
	margin:1em auto;
	padding-bottom:1em;
	border-radius:8px;
	box-shadow:0 2px 3px rgba(0,0,0,0.07);
	
	header{
		border-bottom:3px double @color-4th;
		padding:1em 0;
		padding-bottom:1em;
	
		h1{
			text-align:center;
			font-size:1.3em;
			color:@color-1st;
			font-weight:bolder;
		}

		h2{
			text-align:center;
			font-size:1em;
			color:@color-3rd;
			font-weight:normal;
		}
	}
	
	.button-submit{
		font-weight:regular;
		color:#fff;
		font-size:1em;
		padding:0.8em 2em;
		border-radius:50em;
		border:none;
		background:@color-1st;
		margin:1em auto 0.3em;
		display:block;
		transition:all 0.2s linear;
		
		&:hover{
			background:darken(@color-1st,20%);
		}
	}
	
	ul{
		list-style:none;
		margin:0;
		padding:0;
		
		h3{
			font-weight:normal;
			font-size:1.2em;
		}
		
		.question{
			padding:0 1em 1.5em;
			border-bottom:1px solid @color-4th;
			
			.choice{
				span{
					background:@color-2nd;
					color:#fff;
					font-size:0.8em;
					padding:0.5em 1.5em 0.5em 2em;
					margin:0 1.2em 0 0;
					border-radius:100px;
					position:relative;
					min-width:50px;
					text-align:center;
					display:inline-block;
					transition:all 0.2s linear;
					box-shadow:
							0 0 0 2px rgba(0,0,0,0) inset,
							0 0 0 2px rgba(0,0,0,0);
					
					&:before{
						content:'';
						background:#fff;
						position:absolute;
						top:9px;
						left:7px;
						border-radius:50%;
						width:10px;
						height:10px;
					}
					
					&:after{
						content:'';
						position:absolute;
						z-index:2;
						width:6px;
						height:6px;
						top:11px;
						left:9px;
						transform:scale(0);
						border-radius:50%;
						transition:all 0.3s linear;
					}
					
					&:hover, &:focus{
						background:darken(@color-2nd,20%);
					}
				}
				
				input{
					display:none;
					
					&:checked + span{
						box-shadow:
							0 0 0 2px @color-1st inset,
							0 0 0 2px rgba(0,0,0,0.1);
						
						
						&:after{
							background:@color-1st;
							transform:scale(1);
						}
					}
				}
			}
		}
	}
}
            
          
!

JS

            
              function resultsFromForm(el){
  var results = {};
    $('.question',el).each(function(){
		  var iv = $('input:checked', this)[0].value;
      if(results[iv] == undefined){
			  results[iv] = 1;
			}else{
			  results[iv]++;
		  }
    });
		return results;
}

function calcResults(el){
  if(getKeyOfMaxObjValue(resultsFromForm('.form')) == "dog"){
    alert("You should look for a dog!");
	}else{
		alert("You should look for a cat!");
	}
}

/*
 * Solution bellow taken from
 * https://goo.gl/rBpjQd
 */
function getKeyOfMaxObjValue(obj){
	var max = -Infinity;
  var key;
  for(var prop in obj) {
    // ignore inherited properties
    if(obj.hasOwnProperty(prop)) { 
      if(obj[prop] > max) {
        max = obj[prop];
        key = prop;
      }
    }
  }
	return key;
}
            
          
!
999px

Console