So a makind something with js, and the following error is happening: Uncaught TypeError: Cannot read property ‘value’ of null at addNumber (index.js:27) at index.js:7
Things I already tryied to do: Remove de parentheses from the addNumber on line 7; Do an onclick function instead of an EventLister Remove the .value of the var num (it works but returns 0.0 on the input)
Notice: the code isnt ready yet but im pretty sure that I had to be reciving the message errors that I coded.
var addBtn = document.querySelector('input#addBtn').style.cursor = "pointer"
var analyzeBtn = document.querySelector('input#analyzeBtn').style.cursor = "pointer"
var list = document.getElementById('list')
var num = document.getElementById('num')
var inp = []
addBtn.addEventListenr('click', addNumber())
function isNumber(n){
if(Number(n) >=1 && Number(n) <=100){
return true
} else {
return false
}
}
function inList(n, l) {
if(l.indexOf(Number(n)) != -1){
return true
} else {
return false
}
}
function addNumber (){
if(inList(num.value) && isNumber(num.value, inp)){
inp.push(Number)
list.innerHTML += `${inp}`
} else {
window.alert('Invalid')
}
}
Advertisement
Answer
isNumber function is having two paramters instead of one parameter as defined.
inList function is having one parameter instead of two as defined.