Untitled
const input = document.getElementById('input'); const button = document.getElementById('button'); const ans = document.getElementById('ans'); button.addEventListener('click', function(){ const birthdate = new Date(input.value); if(birthdate){ const today = new Date(); var age = today.getFullYear()- birthdate.getFullYear(); var month = today.getMonth()- birthdate.getMonth(); var date = today.getDate() - birthdate.getDate(); if(month < 0 || (month === 0 && date < 0)){ age--; } ans.innerHTML = `You are ${age} years old`; } }) let string = ""; const buttons = document.querySelectorAll('.button'); buttons.forEach((button) => { button.addEventListener('click', (e) => { if(e.target.innerHTML == '='){ string = eval(string); document.querySelector('input').value = string; }else if(e.target.innerHTML == 'c'){ string = ""; document.querySelector('input').value = string; }else{ string = string + e.target.innerHTML; document.querySelector('input').value = string; } }) }) const button = document.querySelectorAll('.add'); const btn = document.querySelectorAll('.remove'); const counter = document.querySelector('.counter'); let count = 0; button.forEach((button)=> { button.addEventListener('click', function(){ count += 1; counter.textContent = count; alert("Item is added to cart"); }); }); btn.forEach((btn) => { btn.addEventListener('click', function(){ if(count > 0){ count -= 1; counter.textContent = count; } alert("Item is remove from cart"); }); }); document.getElementById('registration').addEventListener('submit', function(e){ e.preventDefault(); let isValid = true; const name = document.getElementById('name').value; const namerror = document.getElementById('namerror'); const mobile = document.getElementById('mobile').value; const mobilerror = document.getElementById('mobilerror'); const mail = document.getElementById('mail').value; const mailerror = document.getElementById('mailerror'); if(name === ""){ namerror.textContent = "please enter name"; isValid = false; }else{ namerror.textContent = ""; } if(mobile.length !== 10){ mobilerror.textContent = "please enter proper mobile no." isValid = false; }else{ mobilerror.textContent = ""; } if(!mail.includes('@')){ mailerror.textContent = "Please enter valid email id"; isValid = false; }else{ mailerror.textContent = "" } if(isValid){ window.location.href = 'thank.html'; } }); let inputodo = document.getElementById('inputodo'); let btn = document.getElementById('btn'); let getodo = document.getElementById('getodo'); btn.addEventListener('click', function(){ let paragraph = document.createElement('p'); paragraph.textContent = inputodo.value; getodo.appendChild(paragraph); inputodo.value = ""; });
Leave a Comment