illcrx illcrx - 4 years ago 184
Javascript Question

console.log is not a function - error in javascript

I am getting the error,

console.log
is not a function but this hasnt been an issue in the past. The error is happening in the first and second
console.log
and it doesnt get past there.

I have semi-colons so I am not sure exactly what the issue is?

document.getElementById("fileToRead").addEventListener("change",function(event) {
var input = document.getElementById("fileToRead");
//Variable for if statement to see if there is a header in the file.
var headerType = false;
console.log(input);
input = event.target.files[0];

console.log('test');

for(var i = 0; i < input.files.length; i++){
var files = input.files[i];
Papa.parse(files, {
header:headerType,
dynamictyping:true,
complete:function(results){
console.log(results);
var input = results.data;
if(headerType === false){
input.forEach(function(input){
jsonData.theData = theData;

var singleEntry = {
"symbol" : input[0],
"date" : input[1],
"open" : input[2],
"high" : input[3],
"low" : input[4],
"close" : input[5],
"volume" : input[6]
};

jsonData.theData.push(singleEntry);
return jsonData;
}); // End forEach loop
} else {

} // End if statement for headerType
document.getElementById("editor").innerHTML = JSON.stringify(jsonData.theData);
} // End Callback Complete

}); // End PapaParse
} // End for loop
});


I have even commented out the code so this is the end result and it still says that
console.log
is not a function!

// This is for the views/admin.ejs file only
//This file describes how the Admin page works, hiding divs and working with the data
// importing


var jsonData = {};
var theData = [];

document.getElementById("fileToRead").addEventListener("change",function(event) {
// var input = document.getElementById("fileToRead")
// //Variable for if statement to see if there is a header in the file.
// var headerType = false;

// input = event.target.files[0];

console.log('test');

// for(var i = 0; i < input.files.length; i++){
// var files = input.files[i];
// Papa.parse(files, {
// header:headerType,
// dynamictyping:true,
// complete:function(results){
// console.log(results);
// var input = results.data;
// if(headerType === false){
// input.forEach(function(input){
// jsonData.theData = theData;

// var singleEntry = {
// "symbol" : input[0],
// "date" : input[1],
// "open" : input[2],
// "high" : input[3],
// "low" : input[4],
// "close" : input[5],
// "volume" : input[6]
// };

// jsonData.theData.push(singleEntry);
// return jsonData;
// }); // End forEach loop
// } else {

// } // End if statement for headerType
// document.getElementById("editor").innerHTML = JSON.stringify(jsonData.theData);
// } // End Callback Complete

// }); // End PapaParse
// } // End for loop
});

Answer Source

I have console redefined as a function further down the code! Complete newbie mistake...... hopefully I wont make this mistake again.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download