So I got these two functions with an if statement which does the same thing.
Which is to check if the value of the input field is empty. if(newTask.value === '')
var newTask = document.getElementById("new-task");
newTask.addEventListener("keyup", function(event) {
event.preventDefault();
if(event.keyCode == 13){
if(newTask.value === ''){
alert('Fill in a task.');
} else{
addTask(newTask.value);
}
}
});
newTaskBtn.onclick = function() {
if(newTask.value === ''){
alert('Fill in a task.');
} else{
addTask(newTask.value);
}
};
What is the recommended way to make my code more efficient?
- Writing another function which does only the checking.
- Writing a function within a function?
Any other ideas are most welcome offcourse.