cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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>
	<head>
		<title>Happy Valentine's Day</title>
		<link href="style.css" rel="stylesheet">
		<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
		<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200" rel="stylesheet">
		<meta name="viewport" content="width=device-width, initial-scale=1">
	</head>
	<body>
	    <div>
	    	<header>
	    		<div id="headerContent">
	    			<h1>The Love Calculator</h1>
	    			<div class="result">
	            		<p>Result: <span id="txtresult"></span></p>
	            		<div class="divider"></div>
	            		<p id="responseLine"></p>
	            	</div>
	    		</div>
	    	</header>
	    	<section class="wrapper">
	    		<form name="loveCalculator">
	    			<p>Enter First Person:<br>
	            		<input type="text" id="personOne" name="personOne">
	            		<hr>
	            	</p>
	            	<p>Enter Second Person:<br>
	            		<input type="text" id="personTwo" name="personTwo">
	            		<hr>
	            	</p>
	            	<div class="errorMessage">
	            		<p id="error"></p>
	            	</div>
	            	<div class="buttonHolder">
	            		<input type="button" id="calculateBtn" name="clickbtn" value="Calculate" onclick="getDetails()">
	            	</div>
	            	<div class="buttonHolder">
	            		<input type="button" id="calculateBtn" name="clickbtn" value="Refresh" onclick="window.location.reload()">
	            	</div>
	    		</form>
	    	</section>
	        <script src="main.js"></script>
	    <div>
	</body>
</html>
            
          
!
            
              body {
	margin: 0;
	padding: 0;
}

header {
	position: relative;
	height: 500px;
	background: #DC758F;
	color: #FFF;
}

p {
	font-size: 1.25em;
	font-family: 'Source Sans Pro', sans-serif;
	margin: 10px 0;
}

form p {
  margin-top: 30px;
}

#headerContent {
	position: absolute;
	top: 50%;
    left: 50%;
    margin-right: -50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

#headerContent h1, 
#headerContent h2, 
#headerContent p {
	font-family: 'Lobster', cursive;
}

#headerContent h1 {
	font-size: 4em;
}

#headerContent h2 {
	font-size: 2em;
}

#headerContent p {
	font-size: 2em;
}

section {
	padding: 100px 20px;
}

section p {
	color: #a6a6a6;
}

.wrapper {
	max-width: 100%;
}

input[type="text"] {
  display: block;
  font-family: 'Source Sans Pro', sans-serif;
  font-weight: bold;
  margin: 0;
  width: 100%;
  font-size: 18px;
  padding-top: 10px;
  border: none;
  outline: none;
  color: #a6a6a6;
}

input[type="text"]:focus {
	border: 2px;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
    outline: none;
}

input[type=button] {
	width: 100%;
    background:#a6a6a6; 
    cursor:pointer;
    color: #FFF;
    border: 0;
    font-family: 'Lobster', cursive;
    font-size: 1.25em;
    padding: 15px;
    margin-top: 15px;
}

input[type=button]:hover {
    background:#bfbfbf; 
}

hr {
	border: 0;
	border-bottom: 1px solid #a6a6a6;
	margin: 0;
}

.buttonHolder {
	width: 100%;
	text-align: center;
}

.result {
	padding: 30px;
}

@media screen and (min-width: 800px) {
    
	.wrapper {
		margin: 0 auto;
		max-width: 70%;
	}

}

.divider {
	display: block;
	width: 40px;
	border: 4px solid #FFF;
	margin: 20px auto 0 auto;
}

.errorMessage p {
	color: #DC758F;
}





            
          
!
            
              function getDetails() {

	var personOne = document.forms["loveCalculator"]["personOne"].value;
	var personTwo = document.forms["loveCalculator"]["personTwo"].value;

	validateForm(personOne, personTwo);
}

function validateForm(nameOne, nameTwo) {

	var inputOne = nameOne;
	var inputTwo = nameTwo;

	if ( inputOne == "" || inputTwo == "") {
	 	var error = "Please fill out all fields.";
 		document.getElementById('error').innerHTML = error;
	}
	else {
	 	calculate(inputOne, inputTwo);
	}
}

function calculate(nameOne, nameTwo) {

	var error = "";
 	document.getElementById('error').innerHTML = error;

	var inputOne = nameOne;
	var inputTwo = nameTwo;

	var percentage = Math.floor(Math.random() * 100) + 1;

	var result ="<strong> " + nameOne + "</strong>" + " & " + "<strong>" + 
	nameTwo + "</strong>" + " are " + "<strong>" + percentage + "</strong>" + "% Compatible.";
 	document.getElementById('txtresult').innerHTML = result;

 	document.getElementById("calculateBtn").disabled = true;
	document.body.scrollTop =document.documentElement.scrollTop = 0;

 	response(percentage);

}

function response(percentage) {

	var responses = [
 			"None. None at all.",
 			"Not much chemistry.", 
 			"Possibly a couple of glances, but nothing to get excited about.",
			"Starting to show some promise.",
 			"You're half way there!",
 			"There is a real spark!",
			"Match made in heaven!",
			"This is love.",
 			"These two need to be together.", 
 	];

	var value = percentage;

	var responseLine = document.getElementById('responseLine');

	 	if (value >= 0 && value < 10)
		{
			responseLine.innerHTML = responses[0];
		}

		else if (value >= 10 && value < 20) {
			responseLine.innerHTML = responses[1];
		}

		else if (value >= 20 && value < 30) {
			responseLine.innerHTML = responses[2];
		}

		else if (value >= 30 && value < 40) {
			responseLine.innerHTML = responses[3];
		}

		else if (value >= 50 && value < 60) {
			responseLine.innerHTML = responses[4];
		}

		else if (value >= 60 && value < 70) {
			responseLine.innerHTML = responses[5];
		}

		else if (value >= 70 && value < 80) {
			responseLine.innerHTML = responses[6];
		}

		else if (value >= 80 && value < 90) {
			responseLine.innerHTML = responses[7];
		}

		else if (value >= 90 && value <= 100) {
			responseLine.innerHTML = responses[8];
		}


}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console