Created
July 3, 2014 00:15
-
-
Save maereed/357a4a5c5394e2d4bb13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title></title> | |
<style> | |
body, input, button { | |
font-size: 20pt; | |
} | |
</style> | |
</head> | |
<body> | |
<form> | |
<input type="text" id="jobTitle" placeholder="Job Title" /> | |
<input type="text" id="hometown" placeholder="Hometown" /> | |
<input type="text" id="partner" placeholder="Partner" /> | |
<input type="text" id="children" placeholder="Children" /> | |
<button type="submit" id="submit" >Submit</button> | |
</form> | |
<div id="message"></div> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script> | |
/** | |
* @exercise 1 - lifeLine | |
* @description takes children, partner's name, hometown, and job | |
* @returns 'You are a W from X and married to Y with Z kids.' | |
**/ | |
// Create function with name tellFortune and appropriate parameters | |
// Take 4 arguments: number of children, partner's name, hometown, job title. | |
var lifeLine = function( jobTitle, hometown, partner, children ) { | |
// Get first letter and make it lowercase | |
var firstLetter = jobTitle.charAt(0).toLowerCase(); | |
// Check if first letter of jobTitle is a, e , i, o, or u | |
if(firstLetter === 'a' || firstLetter === 'e' || firstLetter === 'i' || firstLetter === 'o' || firstLetter === 'u') { | |
var a = 'an '; | |
} else { | |
var a = 'a '; | |
} | |
// Define string variable that will have that output | |
var whateverYouWant = "You are " + a + jobTitle + " from " + hometown + " and married to " + partner + " with " + children + " kids."; | |
// Return that string | |
return whateverYouWant; | |
}; | |
$("#submit").on('click', function (e){ | |
e.preventDefault(); | |
var jobTitle = $("#jobTitle").val(); | |
var hometown = $("#hometown").val(); | |
var partner = $("#partner").val(); | |
var children = $("#children").val(); | |
var message = lifeLine(jobTitle,hometown,partner,children); | |
$("#message").html(message); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment