-1
Guys, I’m taking a course to learn Javascript and I’ve been in this problem for a long time and I can’t understand what happens.
I need to create a function that allows me to count how many times one of the car plates appears in this array. I can perform normally when I do not pass the parameter to the function, but when I put the parameter and call the function I get the error "Uncaught Typeerror: placas is Undefined", but the variable plate is set yes, maybe it’s something simple that I missed, I do not know.
Without passing the cards array as parameter:
<script>
var placas = [
'RXB-2525', 'AKX-3333', 'ORO-7142','RXB-2525', 'AKX-3333', 'ORO-7142',
'AKX-3333', 'RXB-2525', 'AKX-3333','AKX-3333', 'RXB-2525', 'AKX-3333','RXB-2525', 'AKX-3333', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'AKX-3333', 'RXB-2525','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'ORO-7142', 'ORO-7142',
'ORO-7142', 'RXB-2525', 'AKX-3333','AKX-3333', 'ORO-7142', 'ORO-7142',
'AKX-3333', 'RXB-2525', 'AKX-3333','AKX-3333', 'RXB-2525', 'AKX-3333',
'RXB-2525', 'AKX-3333', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'AKX-3333', 'RXB-2525','AKX-3333', 'AKX-3333', 'RXB-2525'
]
function calcularNumeroDeEntradas() {
var cont = 0
for(var i = 0; i<=placas.length;i++) {
if (placas[1] == [i]) {
cont++;
}
}
return cont;
}
When I pass the array as a function parameter:
<script>
var placas = [
'RXB-2525', 'AKX-3333', 'ORO-7142','RXB-2525', 'AKX-3333', 'ORO-7142',
'AKX-3333', 'RXB-2525', 'AKX-3333','AKX-3333', 'RXB-2525', 'AKX-3333','RXB-2525', 'AKX-3333', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'AKX-3333', 'RXB-2525','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'ORO-7142', 'ORO-7142',
'ORO-7142', 'RXB-2525', 'AKX-3333','AKX-3333', 'ORO-7142', 'ORO-7142',
'AKX-3333', 'RXB-2525', 'AKX-3333','AKX-3333', 'RXB-2525', 'AKX-3333',
'RXB-2525', 'AKX-3333', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'AKX-3333', 'RXB-2525','AKX-3333', 'AKX-3333', 'RXB-2525'
]
function calcularNumeroDeEntradas(placas) {
var cont = 0
for(var i = 0; i<=placas.length;i++) {
if (placas[1] == [i]) {
cont++;
}
}
return cont;
}
function calcularNumeroDeEntradas(placas) {}
indicates that you must pass a parameter in order to be able to access the function, that is, when calling it, you must invoke it in the following way:var placas = ['...', '...']; calcularNumeroDeEntradas(placas);
. I recommend reading https://answall.com/a/383294/99718– Valdeir Psr