1
I’m starting to learn JavaScript
and I care about writing a code redundant/repetitive, has some more appropriate way of converting strings from prompt
in numbers before inserting into array
?
function getPoints() {
var point
var points = []
for (var i = 0; i <= 2; i++) {
point = prompt(`Pontuação obtida no exercício ${i+1}`)
points[i] = Number(point)
}
return points
}
It did not work my answer Fabiana?
– novic
It did. The way you put it, using the push looks better, really. But my question was whether the conversion should be more summarized, without using a variable like that of the point to store the converted value before inserting it into the array.
– Fabiana Fieldkircher
There are no problems in creating variable, which will be used which is the case, the problem of your code was the lack of test and only enter numerical data
– novic