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 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>
	<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);
  
  if (inputOne === "Michael" && inputTwo ==="Omar") {
    percentage = 100; 
  }

}

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
🕑 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.
Loading ..................

Console