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.
JavaScript
x
34
34
1
var addBtn = document.querySelector('input#addBtn').style.cursor = "pointer"
2
var analyzeBtn = document.querySelector('input#analyzeBtn').style.cursor = "pointer"
3
var list = document.getElementById('list')
4
var num = document.getElementById('num')
5
var inp = []
6
7
addBtn.addEventListenr('click', addNumber())
8
9
function isNumber(n){
10
if(Number(n) >=1 && Number(n) <=100){
11
return true
12
} else {
13
return false
14
}
15
}
16
17
function inList(n, l) {
18
if(l.indexOf(Number(n)) != -1){
19
return true
20
} else {
21
return false
22
}
23
}
24
25
function addNumber (){
26
27
if(inList(num.value) && isNumber(num.value, inp)){
28
inp.push(Number)
29
list.innerHTML += `${inp}`
30
} else {
31
window.alert('Invalid')
32
}
33
}
34
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.