Skip to main content
I am trying to built a age calculator. calculator take input from calendar and output age. but this program don't show anything.

Agecalculator.html

<template>

<lightning-card title="Age Calculator">

<lightning-button variant="brand" label="Calculate" slot="actions" onclick={calculateDOB}></lightning-button>

<p class="slds-p-horizontal_small">

<lightning-input type="date" name="BirthDate" label="Enter Your Date Of Birth" placeholder="type here..." value={birthdate} onchange= {handleChangeNum1}></lightning-input>

result---{result}

</p>

</lightning-card>

</template>

AgeCalculator.js

export default class AgeCalculator extends LightningElement {

@track result;

@track birthdate;

today = new Date();

handleChangeNum1(event){

const inpurdate = event.target.name;

const inputvalue= event.target.value;

if(inpurdate=='BirthDate'){

this.birthdate=inputvalue;

}

}

calculateDOB (event) {

this.result=today.getfullyear-this.birthdate.getfullyear;

}

}

 
4 réponses
  1. 10 avr. 2021, 16:51

    Hi Yasir,

     

       getFullYear is a method in Javascript which works on Date object. So please try 

       this.result = this.today.getFullYear() - this.birthdate.getFullYear();

     

    Thank you,

    Vinay.

0/9000