Post as many JavaScript errors as you can by breaking the provided code. Try to come up with explanation of the error you get. Prizes for the weirdest error.
Last active
May 24, 2017 14:29
-
-
Save airportyh/ad6abdadd2a480095e17af8ba26f6214 to your computer and use it in GitHub Desktop.
JavaScript Errors
Here's the Error:
haiku.js:13 Uncaught SyntaxError: Unexpected token < haiku.js:13
Here's the Code:
var haiku = [
'the wind of Fuji',
'I\'ve brought on my fan',
'a gift from Edo'
];
var resultLines = [];
for (var i = 0; i < haiku.length; i++) {
var line = haiku[i];
var words = line.split(' ');
var resultWords = [];
for (var j = 0, j < words.length; j++) {
var word = words[j];
var reversed = word.split('').reverse().join('');
resultWords.push(reversed);
resultLinespush(resultWords.join(' ');
}
console.log(resultLines.join('\n'));
Error message:
$(document).ready(function() {
^
ReferenceError: $ is not defined
at Object.<anonymous> (/Users/dtolliver/Desktop/DigitalCrafts/4-17immersive/debugging/weather.js:3:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
Code below:
var APPID = 'd572e3897b56c1638fada0388125c161';
$(document).ready(function() { // <----- Line 3
$('#button').click(function() {
$.ajax({
method: 'param', //<----- Change was here
url: 'http://api.openweathermap.org/data/2.5/weather',
data: {
q: $('#q').val(),
units: 'imperial',
APPID: APPID
},
success: function(data) {
$('#display').html(
// '<h2>Forecast for ' + data.name + ':</h2>' +
'Temperature: ' + data.main.temp + '°F<br>' +
'Hi: ' + data.main.temp_max + '°F<br>' +
'Lo: ' + data.main.temp_min + '°F<br>' +
data.weather[0].description + '<br>' +
'<img src="http://openweathermap.org/img/w/' + data.weather[0].icon + '.png">'
);
}
})
});
});
Not sure why changing GET to param broke the $
Uncaught TypeError: resultWords.push is not a function haiku.js:16
at haiku.js:16
var haiku = [
'the wind of Fuji',
'I\'ve brought on my fan',
'a gift from Edo'
];
var resultLines = [];
for (var i = 0; i < haiku.length; i++) {
var line = haiku[i];
var words = line.split(' ');
var resultWords = {};
for (var j = 0; j < words.length; j++) {
var word = words[j];
var reversed = word.split('').reverse().join('');
resultWords.push(reversed);
}
resultLines.push(resultWords.join(' '));
}
console.log(resultLines.join('\n'));Replaced var resultWords = [] with var resultWords = {}
Uncaught TypeError: Assignment to constant variable. haiku.js:9
at haiku.js:9
var haiku = [
'the wind of Fuji',
'I\'ve brought on my fan',
'a gift from Edo'
];
var resultLines = [];
for (const i = 0; i < haiku.length; i++) {
var line = haiku[i];
var words = line.split(' ');
var resultWords = [];
for (var j = 0; j < words.length; j++) {
var word = words[j];
var reversed = word.split('').reverse().join('');
resultWords.push(reversed);
}
resultLines.push(resultWords.join(' '));
}
console.log(resultLines.join('\n'));Updated var i = 0 to const i = 0
Temperature: 66.4°F
Hi: 68°F
Lo: 64.4°F
undefined //description
no error message in the console...
var APPID = 'd572e3897b56c1638fada0388125c161';
$(document).ready(function() {
$('#button').click(function() {
$.ajax({
method: 'GET',
url: 'http://api.openweathermap.org/data/2.5/weather',
data: {
q: $('#q').val(),
units: 'imperial',
APPID: APPID
},
success: function(data) {
$('#display').html(
// '<h2>Forecast for ' + data.name + ':</h2>' +
'Temperature: ' + data.main.temp + '°F<br>' +
'Hi: ' + data.main.temp_max + '°F<br>' +
'Lo: ' + data.main.temp_min + '°F<br>' +
data.weather.description + '<br>' + // error in line 19
'<img src="http://openweathermap.org/img/w/' + data.weather[0].icon + '.png">'
);
}
})
});
});
Here's the error:
Uncaught SyntaxError: Unexpected identifier weather.js:10
var APPID = 'd572e3897b56c1638fada0388125c161';
$(document).ready(function() {
$('#button').click(function() {
$.ajax({
method: 'GET',
url: 'http://api.openweathermap.org/data/2.5/weather',
data: {
q: $('#q').val(),
units: 'imperial'
APPID: APPID
},
success: function(data) {
$('#display').html(
// '<h2>Forecast for ' + data.name + ':</h2>' +
'Temperature: ' + data.main.temp + '°F<br>' +
'Hi: ' + data.main.temp_max + '°F<br>' +
'Lo: ' + data.main.temp_min + '°F<br>' +
data.weather.description + '<br>' +
'<img src="http://openweathermap.org/img/w/' + data.weather[0].icon + '.png">'
);
}
})
});
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the error:
Uncaught TypeError: Cannot read property 'split' of undefinedat haiku.js:11(anonymous) @ haiku.js:11Here's the code: