Last active
July 30, 2016 07:13
-
-
Save CSRaghunandan/5038b5b8c17c046c73605a20221f4b41 to your computer and use it in GitHub Desktop.
WireDelta Sample Test
This file contains hidden or 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
var calculateAgeManual = function (birthYear, currentYear) { | |
var age = currentYear - birthYear; | |
console.log("You are either " + age + " or " + (age - 1) + " years old"); | |
}; | |
// gets the current year from javascript | |
var calculateAgeAutomatic = function (birthYear) { | |
var date = new Date(), | |
currentYear = date.getFullYear(), | |
age = currentYear - birthYear; | |
console.log("You are either " + age + " or " + (age - 1) + " years old"); | |
}; | |
var test = function () { | |
/* output should be | |
You are either 24 or 23 years old | |
You are either 14 or 13 years old | |
You are either 100 or 99 years old */ | |
calculateAgeManual(1992, 2016); | |
calculateAgeManual(2000, 2014); | |
calculateAgeManual(1900, 2000); | |
/* output should be | |
You are either 24 or 23 years old | |
You are either 16 or 15 years old | |
You are either 116 or 115 years old */ | |
calculateAgeAutomatic(1992); | |
calculateAgeAutomatic(2006); | |
calculateAgeAutomatic(1900); | |
}; | |
// uncomment to run the test inputs | |
//test(); |
This file contains hidden or 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
var calculateSupply = function (age, amountPerDay) { | |
// let max age be 100 years old | |
var MAX_AGE = 100, | |
amountConsumed = Math.round(age * amountPerDay), | |
amountForMaxAge = Math.round(MAX_AGE * amountPerDay), | |
amountNeeded = amountForMaxAge - amountConsumed; | |
// output the result to console | |
console.log("You will need " + amountNeeded + " snacks to last you until the" | |
+ " ripe old age of " + MAX_AGE); | |
}; | |
var test = function () { | |
/* output should be: | |
You will need 120 snacks to last you until the ripe old age of 100 | |
You will need 100 snacks to last you until the ripe old age of 100 | |
You will need 35 snacks to last you until the ripe old age of 100 */ | |
calculateSupply(20, 1.5); | |
calculateSupply(50, 2); | |
calculateSupply(30, 0.5); | |
}; | |
//uncomment to run the test inputs | |
//test(); |
This file contains hidden or 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
var calcCircumference = function (radius) { | |
var circumference = 2 * Math.PI * radius; | |
console.log("The circumference of the circle with radius " | |
+ radius + " is " + circumference); | |
}; | |
var calcArea = function (radius) { | |
var area = Math.PI * radius * radius; | |
console.log("The Area of the circle with radius " + | |
radius + " is " + area); | |
}; |
This file contains hidden or 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
var celsiusToFahrenheit = function () { | |
var celsius = prompt("Enter the temperature in Celsius"), | |
fahrenheit = (9 / 5 * celsius) + 32; | |
console.log(celsius + "C is " + fahrenheit + "F"); | |
}; | |
var fahrenheitToCelsius = function () { | |
var fahrenheit = prompt("Enter the temperature in Fahrenheit"), | |
celsius = (fahrenheit - 32) * 5 / 9; | |
console.log(fahrenheit + "F is " + celsius + "C"); | |
}; |
This file contains hidden or 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title>WireDelta Sample Test.</title> | |
<meta charset="utf-8" /> | |
<style> | |
body { | |
background-color: lightgrey; | |
} | |
.h1 { | |
text-align: center; | |
font-size: 3.0em; | |
font-family: 'Helvetica Neue', sans-serif; | |
font-weight: bold; | |
} | |
.button { | |
background-color: #4CAF50; /* Green */ | |
border-style: solid; | |
color: white; | |
padding: 15px 32px; | |
text-align: center; | |
border-radius: 8px; | |
font-size: 16px; | |
-webkit-transition-duration: 0.4s; | |
transition-duration: 0.4s; | |
font-family: 'Helvetica Neue', sans-serif; | |
} | |
.button:hover { | |
background-color: #e7e7e7; | |
color: black; | |
} | |
</style> | |
</head> | |
<body> | |
<h1 class="h1"> WireDelta Sample Test</h1> | |
<h2> Click on the function you want to execute :-</h2> | |
<button type="click" class="button">Age calculator</button> <br><br> | |
<button type="click" class="button">Snack lifetime supply calculator</button><br><br> | |
<button type="click" class="button">Calculate Area</button> | |
<button type="click" class="button">Calculate Circumference</button><br><br> | |
<button type="click" class="button">Celcius to Fahrenheit</button> | |
<button type="click" class="button">Fahrenheit to Celsius</button> | |
<!-- add test1-4 script files --> | |
<script src="age-calculator.js"></script> | |
<script src="lifetime-supply.js"></script> | |
<script src="temperature-converter.js"></script> | |
<script src="geometrizer.js"></script> | |
<!-- add the test5 script file --> | |
<script src="test5.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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
(function () { | |
// get all the buttons defined in HTML | |
buttons = document.getElementsByTagName("button"); | |
// add events to all the buttons | |
buttons[0].addEventListener("click",function () { | |
var birthYear = prompt("Enter your birth year"); | |
calculateAgeAutomatic(birthYear); | |
}, false); | |
buttons[1].addEventListener("click",function () { | |
var age = prompt("Enter your age"), | |
amountPerDay = prompt("Enter amount of snacks you eat per day"); | |
calculateSupply(age, amountPerDay); | |
}, false); | |
buttons[2].addEventListener("click",function () { | |
var radius = prompt("Enter the radius of the circle"); | |
calcArea(radius); | |
}, false); | |
buttons[3].addEventListener("click",function () { | |
var radius = prompt("Enter the radius of the circle"); | |
calcCircumference(radius); | |
}, false); | |
buttons[4].addEventListener("click", celsiusToFahrenheit, false); | |
buttons[5].addEventListener("click", fahrenheitToCelsius, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
p.s. Output for all the functions are shown using console.log