Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
function and scope assignment
- Loading branch information
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!doctype html> | ||
<html class="no-js" lang=""> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | ||
<title></title> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<link rel="apple-touch-icon" href="apple-touch-icon.png"> | ||
<!-- Place favicon.ico in the root directory --> | ||
|
||
<link rel="stylesheet" href="css/normalize.css"> | ||
<link rel="stylesheet" href="css/main.css"> | ||
<script src="js/vendor/modernizr-2.8.3.min.js"></script> | ||
</head> | ||
<body> | ||
<!--[if lt IE 8]> | ||
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | ||
<![endif]--> | ||
|
||
<div id="log"> | ||
<h2>The Log</h2> | ||
<p id="lede"> | ||
There should be a new paragraph for every javascript line you write to the console. See Instructions in the "Javascript" window. WRITE YOUR CODE BELOW THE COMMENT BLOCKS FOR READABILITY. <strong>This paragraph should remain!</strong> | ||
</p> | ||
</div> | ||
|
||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | ||
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script> | ||
<script src="js/plugins.js"></script> | ||
<script src="js/main.js"></script> | ||
|
||
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. --> | ||
<script> | ||
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]= | ||
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date; | ||
e=o.createElement(i);r=o.getElementsByTagName(i)[0]; | ||
e.src='https://www.google-analytics.com/analytics.js'; | ||
r.parentNode.insertBefore(e,r)}(window,document,'script','ga')); | ||
ga('create','UA-XXXXX-X','auto');ga('send','pageview'); | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* | ||
* Write a function that will simultaneously perform a console.log() | ||
* and write a new paragraph to the #log div with whatever text you give it. | ||
* You are just creating the function, NOT calling it yet. Here, I'll get you started. | ||
* | ||
**/ | ||
|
||
function fancyLog(text) { | ||
console.log(text); | ||
// Now what goes in here? | ||
var log = document.querySelector("#log"); | ||
log.innerHTML += ("<p>" + text + "</p>"); | ||
} | ||
|
||
/** | ||
* | ||
* Write a function that will automatically calcuate the two ages based on a birth | ||
* year and a given year. DO NOT CALL THE FUNCTION YET. The function should use your fancyLog() | ||
* function above. I'll get you started here, too. | ||
* | ||
*/ | ||
|
||
function calculateAges(currentyear,birthyear) { | ||
var age1 = currentyear-birthyear; | ||
// Calculate age2 properly. | ||
var age2 = age1 - 1; | ||
// Now call fancyLog() with the text "If you were born in {birthYear}, your age could be {age1} or {age1}." | ||
fancyLog("If you were born in " + birthyear + " your age could be " + age1 + " or " + age2 + ".") | ||
} | ||
|
||
/** | ||
* Now, write a function that will convert a value (kilometers) to miles. | ||
* Your function should RETURN the value in miles. | ||
* DO NOT CALL THE FUNCTION YET | ||
* I'll get you started. | ||
*/ | ||
|
||
function kilometersToMiles(kilo){ | ||
|
||
// Do the converstion here and set a variable "miles" | ||
var miles = kilo * .621; | ||
|
||
return miles; | ||
} | ||
|
||
/** | ||
* Now, we're going to call our functions! | ||
* Write a call to fancyLog() and log/display "Let's get started with functions!" | ||
*/ | ||
fancyLog("Let's get started with functions!") | ||
/** | ||
* Use javascript prompt(); to ask the user for their birth year. | ||
* Use the results from that prompt() to call "calculateAges()" | ||
* FOR 5 BONUS POINTS, use javascript to dynamically get the | ||
* current year instead of hand-coding it | ||
* Your calculateAges() function should automatically fancyLog(); | ||
*/ | ||
var promptResults = prompt("Put in your birth year"); | ||
var thisYear = 2016; | ||
calculateAges(thisYear, promptResults); | ||
|
||
|
||
/** | ||
* Call your kilometersToMiles() function to convert 5K to miles. Store the returned value in a | ||
* variable here. Use fancyLog() to display/log "5 kilometers is equal to {miles} miles." | ||
*/ | ||
var storeKilos = kilometersToMiles(5); | ||
fancyLog("5 kilometers is equal to " + storeKilos + " miles.") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Avoid `console` errors in browsers that lack a console. | ||
(function() { | ||
var method; | ||
var noop = function () {}; | ||
var methods = [ | ||
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', | ||
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', | ||
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', | ||
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn' | ||
]; | ||
var length = methods.length; | ||
var console = (window.console = window.console || {}); | ||
|
||
while (length--) { | ||
method = methods[length]; | ||
|
||
// Only stub undefined methods. | ||
if (!console[method]) { | ||
console[method] = noop; | ||
} | ||
} | ||
}()); | ||
|
||
// Place any jQuery/helper plugins in here. |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.