Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
3.4 kB
1
Indexable
Never
/* 
    Created on : May, 2019 
    Author     : Liisa Auer, Oulu University of Applied Sciences
    Licence    : CC-BY-4.0
*/

/*
 * Student name :
 * Started date :
 * Ended   date :
 * 
 */
function ageCalc (a){
    let date = new Date();
    let yearNow = date.getFullYear();
    return yearNow-a
}

function v01() {
    let year = Number(document.getElementById('year').value)
    let age = ageCalc(year)
    let allowStatement = ' '
    if (age>=18){
        allowStatement = `Welcome` 
    }else {
        allowStatement = `Too young`
    }
    document.getElementById('allow').innerHTML = allowStatement;
}

function v02() {
    let number1 = Number(document.getElementById('number1').value)
    let number2 = Number(document.getElementById('number2').value)

    if (number1>number2){
        document.getElementById('smaller').innerHTML = 'Number 2';
    }else{
        document.getElementById('smaller').innerHTML = 'Number 1';
    } 

}

function v03() {
    const NEG = "One of the numbers is negative."
    const POS = "Both numbers are either positive or negative."

    let number1 = Number(document.getElementById('number1').value)
    let number2 = Number(document.getElementById('number2').value)

    if (number1 < 0 || number2 < 0) {
        document.getElementById('negative').innerHTML = NEG ;
    }else {
        document.getElementById('negative').innerHTML = POS ;
    }
}

function v04() {
    const REC = "rectangle";
    const SQ = "square";

    let side1 = Number(document.getElementById('side1').value)
    let side2 = Number(document.getElementById('side2').value)

    if(side1===side2){
        document.getElementById('square').innerHTML = SQ ;
    }else {
        document.getElementById('square').innerHTML = REC ;
    }

}

function v05() {
    const EVEN = "even";
    const ODD = "odd";

    let number = Number(document.getElementById('number3').value)
    if (number%2===0){
        document.getElementById('even').innerHTML = EVEN ;
    }else{
        document.getElementById('even').innerHTML = ODD ;
    }

}

function v06() {
    let number = Number(document.getElementById('number3').value)
    if (number>0){
        document.getElementById('positive').innerHTML = 'positive' ;
    }else{
        document.getElementById('positive').innerHTML = 'negative' ;
    }
}

function v07() {
    let array = [];

    let digit_a = Number(document.getElementById('digit_a').value)
    let digit_b = Number(document.getElementById('digit_b').value)
    let digit_c = Number(document.getElementById('digit_c').value)
    let digit_d = Number(document.getElementById('digit_d').value)

    array.push(digit_a,digit_b,digit_c,digit_d)
    array.sort(function(a, b){return a-b})

    document.getElementById('smallest').innerHTML = array[0]
    let lenght = array.length-1
    document.getElementById('biggest').innerHTML = array[lenght] ;
}

function v08() {
    let leapYear = 'This is a leap year'
    let notLeapYear = 'This is not a leap year'

    let year = Number(document.getElementById('yearx').value)
    if(year%4 === 0 || year%100===0 || year%400===0){
        document.getElementById('leap_year').innerHTML = leapYear
    }
    else {
        document.getElementById('leap_year').innerHTML = notLeapYear
    }
}