CPSDay1a
Implementing Algorithms: Categorizing
Using Conditional Statements for Selective Computation
var age1 = 8;
var age2 = 13;
var age3 = 23;
var currentAge = age3;
if (currentAge < 13)
{
console.log("This person is a pre-teen");
}
if (currentAge > 12 && currentAge < 20)
{
console.log("This person is a teenager");
}
if (currentAge >= 21)
{
console.log("This has all rights as an adult");
}
// Finding the Largest
var x = 12;
var y = 68;
var z = 68;
if (x >= y && x >= z)
{
console.log(x + " is the biggest of " + y + " and " + z);
}
else if (y >= x && y >= z)
{
console.log(y + " is the biggest of " + x + " and " + z);
}
else if (z >= x && z >= y )
{
console.log(z + " is the biggest of " + x + " and " + y);
}
var x=10;
var y=20;
var z=30;
if (x >= y && x >= z)
{
console.log("x is the largest number " + x);
}
else if (y>=x && y>=z)
{
console.log("Y is the largest "+y);
}
else
{
console.log ("Z is the largest " +z);
}
var ages = [8, 13, 18, 20, 21, 25];
//var age1 = 8;
//var age2 = 13;
//var age3 = 18;
//var age4 = 20;
//var age5 = 21;
//var age6 = 25;
//var currentAge = age6;
for (var student = 0; student < ages.length; student++)
{
var currentAge = ages[student];
if (currentAge < 13)
{
console.log("This person is a pre-teen." + currentAge);
}
if (currentAge >= 13 && currentAge < 18)
{
console.log("This person is a teenager." + currentAge);
}
if (currentAge >= 18 && currentAge <20 )
{
console.log("This person is a teenager, but has voting rights." + currentAge);
}
if (currentAge >= 20 && currentAge < 21 )
{
console.log("You are not a teenager nor can you purchase alcohol." + currentAge);
}
if (currentAge >= 21 && currentAge <25 )
{
console.log("This person has all rights as an adult." + currentAge);
}
if (currentAge >= 25 )
{
console.log("This person has all rights as an adult INCLUDING discounted car rental!" + currentAge);
}
}