i'm having trouble with a little code i'm writing in javascript which is supposed to return a table with a column for month and a column for profits. Everything is okay except it seems that i got a undefined value out of nowhere. Here's the code :
"use strict";
var i, mois, ventes, a, b;
mois=["Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"];
ventes=[120,500,350,400,600,890,450,100,250,300,650,450];
function Fventes(a, b) {
for (i=0; i<12; i++) {
document.write('<tr><td>', a[i],'</td><td>',b[i],'</td></tr>');
}
}
document.write('<table><thead><td>Tableau des ventes</td></thead><tbody>');
document.write(Fventes(mois, ventes));
document.write('</tbody></table>');
The undefined value appears before the 1st document write, as if i was calling the value of an empty variable.
document.writeand consider using DOM Methods instead; i.e.parent_node.appendChild(table_root_node)