Skip to content

Instantly share code, notes, and snippets.

@poornachandratejasvi
Last active February 23, 2017 07:45
Show Gist options
  • Save poornachandratejasvi/6cb28e552ecf22082951ff84733729bc to your computer and use it in GitHub Desktop.
Save poornachandratejasvi/6cb28e552ecf22082951ff84733729bc to your computer and use it in GitHub Desktop.
wiredelta answers
function calculateAge(birthyear, currentyear) {
var age = currentyear - birthyear;
document.write("You are either " + age + " or " + (age - 1));
}
function calculateAge(birthyear){
var d = new Date();
var n= d.getFullYear();
var age =n-birthyear;
document.write("You are either " + age + " or " + (age-1));
}
//calculateAge(1984,2017)
//calculateAge(1984)
//calculateAge(2000)
function calculateSupply(age,amountperday) {
var maxage = 80;
var total = (amountperday * 365) * (maxage - age);
document.write("You will need "+ Math.round(total) +" to last you until the ripe old age of "+ maxage);
}
//calculateSupply(23,20)
//calculateSupply(25,20.25)
function calcCircumfrence(radius) {
var cm = Math.PI * 2*radius;
document.write("The circumference is " + cm);
}
function calcArea(radius) {
var area = Math.PI * radius*radius;
document.write("The area is " + area);
}
//calcCircumfrence(25)
//calcArea(25)
function celsiusToFahrenheit(celsius){
var c=celsius;
var ctof = (c*9)/5 + 32;
document.write(""+ c +"°C is " + ctof+"°F");
}
function fahrenheitToCelsius(fahrenheit) {
var f=fahrenheit;
var ftoc = ((f - 32)*5)/9;
document.write(""+ f+"°F is " +ftoc+"°C");
}
//celsiusToFahrenheit(10);
//fahrenheitToCelsius(10);
function myFunction() {
var x = document.getElementById('myDIV');
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
<html>
<style>
h4 {
color:red;
}
.red
{
color:green;
}
</style>
<script type="text/javascript" src="1.js"></script>
<body>
<h4> THE AGE CALCULATOR </h4></br>
birth year<input type="text" id="age">
current year <input type="text" id="current">
<button type="button" onclick="calculateAge(document.getElementById('age').value,document.getElementById('current').value)" style="color:blue" >compute</button><br>
birth year<input type="text" id="age2">
<button type="button" onclick="calculateAge(document.getElementById('age2').value)" style="color:blue">compute</button>(auto current year is taken)<br>
</br>
<hr>
<h4 >THE LIFETIME SUPPLY CALCULATOR</h4></br>
your age<input type="text" id="ages">
amount per day <input type="text" id="amount">
<button type="button" onclick="calculateSupply(document.getElementById('ages').value,document.getElementById('amount').value)" style="color:blue">compute</button><br>
</br></br>
<hr>
<h4 >THE GEOMETRIZER</h4></br>
radius<input type="text" id="rad">
<button type="button" onclick="calcCircumfrence(document.getElementById('rad').value)" style="color:blue">circumference</button>
<button type="button" onclick="calcArea(document.getElementById('rad').value)" style="color:blue"> area</button>
</div>
</br>
</br></br>
<hr>
<h4 >THE TEMPERATURE CONVERTER</h4></br>
<button onclick="myFunction()">click here</button>
<div id="myDIV" style='display:none'>
in celsius<input type="text" id="cel">
<button type="button" onclick="celsiusToFahrenheit(document.getElementById('cel').value)" style="color:blue">ctof</button><br>
in Fahrenheit<input type="text" id="far">
<button type="button" onclick="fahrenheitToCelsius(document.getElementById('far').value)" style="color:blue">ftoc</button><br>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment