O'Reilly Forums: Strange Error On Utils.js - Chapter 3 - Coffee Maker - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Strange Error On Utils.js - Chapter 3 - Coffee Maker The text-utils is giving error when i call the ready coffee function

#1 User is offline   Luciana Machado 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 12-April 09

  Posted 12 April 2009 - 05:15 PM

Everything else on the exercise worked, except the last function, that tells the coffee is ready. When the timer finishes, the javascript errrors at the text-utils code :

Error: el.appendChild is not a function
Source File: http://www.luciana.pro.br/ajax/coffee/text-utils.js
Line: 5


------------- TEXT-UTILS.JS :

function replaceText(el, text) {
if (el != null) {
clearText(el);
var newNode = document.createTextNode(text);
el.appendChild(newNode); <<<<<<<<<<< THE ERROR REFERS TO THIS LINE
}
}

---------------------------------


------------ serveDrink FUNCTION :

function serveDrink()
{
// quando a cafeteira tiver terminado, serve a bebida
if( request.readyState == 4 )
{
if( request.status == 200 )
{
var response = request.responseText;

//descobre quem fez o pedido e de qual cafeteira veio
var maker = response.substring( 0, 1 ); // '2Jim'
var name = response.substring( 1, response.length );

if( maker == "1" )
{
document.getElementById( "coffeemaker1-status" );
replaceText( coffeemaker1-status, "Idle" );
}
else
{
document.getElementById( "coffeemaker2-status" );
replaceText( coffeemaker1-status, "Idle" );
}

alert( name + ", your coffee is ready!" );
}
else
{
alert( "Error! Request status is: " + request.status );
}
}
}

--------------------------------------------

ANY IDEA OF WHAT COULD IT BE ??

THANKS !

[]S

0

#2 User is offline   Jhenna Lopez 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 07-January 12

Posted 07 January 2012 - 06:56 PM

You don't have brackets around a lot of your if clauses so your else if statements break. double check your conditions.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users