Как возвращать переменную в функции?
Как мне возвращать переменную mouth?
createCalendar(calendar, 2021, mouth + 1);
function ListenDate() {
let left_arrow = document.getElementById('left-arrow');
let right_arrow = document.getElementById('right-arrow');
left_arrow.onclick = function() {
mouth -= 1;
console.log(mouth);
return mouth;
};
right_arrow.onclick = function() {
mouth += 1;
console.log(mouth);
return mouth;
};
}
Ответы (1 шт):
Автор решения: Vadim
→ Ссылка
Возвращать никак, только как-то так - функцию calendarUpdate создать, и из кликов отправлять значение туда - для изменения ?
const calendar = document.getElementById('calendar_Probably?');
let mouth = 0;
createCalendar(calendar, 2021, mouth + 1);
const calendarUpdate = (newMounth)=>{
calendar.value = newMounth;
};
const listenDate = ()=>{
const left_arrow = document.getElementById('left-arrow');
const right_arrow = document.getElementById('right-arrow');
left_arrow.onclick = ()=>{
mouth -= 1;
console.log('L', mouth);
calendarUpdate(mouth);
};
right_arrow.onclick = ()=>{
mouth += 1;
console.log('R', mouth);
calendarUpdate(mouth);
};
};