Skip to content

Instantly share code, notes, and snippets.

@airportyh
Last active May 24, 2017 14:29
Show Gist options
  • Select an option

  • Save airportyh/ad6abdadd2a480095e17af8ba26f6214 to your computer and use it in GitHub Desktop.

Select an option

Save airportyh/ad6abdadd2a480095e17af8ba26f6214 to your computer and use it in GitHub Desktop.
JavaScript Errors

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.

@cboe07

cboe07 commented May 24, 2017

Copy link
Copy Markdown

Here's the error:

Uncaught ReferenceError: Invalid left-hand side in assignment                                          weather.js:16 

Here's the code:

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[0].description = '<br>' +
          '<img src="http://openweathermap.org/img/w/' + data.weather[0].icon + '.png">'
        );
      }
    })
  });
});

@VinozzZ

VinozzZ commented May 24, 2017

Copy link
Copy Markdown

ReferenceError: $ is not defined
at eval:3:1
at eval
at n.

Explanation: jQuery is not included in html file

@cshall13

Copy link
Copy Markdown

Here's the error:
Uncaught SyntaxError: missing ) after argument list weather.js:19

Here's the code:

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[0].description + '<br>' 
          '<img src="http://openweathermap.org/img/w/' + data.weather[0].icon + '.png">'
        );
      }
    })
  });
});

@HayesCapers

Copy link
Copy Markdown

Here's the error:
Uncaught Luke, I am your father haiku.js:10

Here's the code:

  'the wind of Fuji',
  'I\'ve brought on my fan',
  'a gift from Edo'
];

var resultLines = [];

for (var i = 0; i < haiku.length; i++) {
  throw "Luke, I am your father"
  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'));```

@MichaelGaynor

MichaelGaynor commented May 24, 2017

Copy link
Copy Markdown

Here's the error:

Uncaught TypeError: Cannot read property 'split' of undefined
    at haiku.js:11
(anonymous) @ haiku.js:11

And 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[j];
  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'));

ghost commented May 24, 2017

Copy link
Copy Markdown

Here is the error:
VM46:16 Uncaught TypeError: resultWords.kush is not a function at :16:17

Here is 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.kush(reversed);
}
resultLines.push(resultWords.join(' '));
}

console.log(resultLines.join('\n'));

@cboe07

cboe07 commented May 24, 2017

Copy link
Copy Markdown

Here's the error:

Uncaught SyntaxError: Unterminated template literal  

Here's the error:

var APPID = 'd572e3897b56c1638fada0388125c161';

$(document).ready(function() {
  $('#button').click(function() {
    $.ajax`{                                                 weather.js:5
      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[0].description + '<br>' +
          '<img src="http://openweathermap.org/img/w/' + data.weather[0].icon + '.png">'
        );
      }
    })
  });
});

Description:
` in place of (

@HayesCapers

HayesCapers commented May 24, 2017

Copy link
Copy Markdown

Here's the error:
Uncaught TypeError: Cannot read property 'split' of undefined
at haiku.js:11
(anonymous) @ haiku.js:11

Here's the code:

  '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[NaN];
  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'));

@nicolasblumenstock

Copy link
Copy Markdown

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'));

@henaege

henaege commented May 24, 2017

Copy link
Copy Markdown

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 $

@merileewheelock

merileewheelock commented May 24, 2017

Copy link
Copy Markdown

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 = {}

@merileewheelock

Copy link
Copy Markdown

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

@csevere

csevere commented May 24, 2017

Copy link
Copy Markdown

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">'
        );
      }
    })
  });
});

@stephenward21

Copy link
Copy Markdown

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