Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

What causes the mis-run?

I am creating a website where you can upload a fact to the Parse backend. So I wrote the code but it does not seem to be working. What is the problem?

<html>
<body>
  <script type="text/javascript">
    Parse.initialize("uZXJE7ChTK3XMvs3Nsf8hE5ivHWiGLpEimGAnUp1", "zJ9PQfiin6ZY9FXSqxFvYmuA9uOhsRz64jTWoExL");

var SomeFacts = Parse.Object.extends("SomeFacts");
var theFacts = new SomeFacts();
var supplyInfo = prompt("Enter information:  ");
theFacts.set( "ActualInformation" , supplyInfo );
theFacts.save(null, {
  success: function(theFacts) {
    alert('New object created with objectId: ' + theFacts.id);
  },
  error: function(theFacts, error) {
    alert('Failed to create new object, with error code: ' + error.message);
  }
});
}
</script>
</body>
</html>

4 Answers

In order to use a JavaScript library, like Jquery or Parse.com's, you need to load it first before your own script. Otherwise your script won't have the necessary code loaded and objects like Parse will be undefined.

Check the docs and/or sample code from Parse.com. It should give the necessary <script> tags to include before your code.

Well. I am in a team right now. So I have this script to the front-end and he initialized the actual Parse. But even for him it is not working.

<html>
<center><b><i><u><h1><font color="green">
<head> Welcome to Evergreen!
<title>  Evergreen
</title>
<script src="//www.parsecdn.com/js/parse-1.6.7.min.js"></script>
</head></h1></u></i></b></center></font> 
<body bgcolor="white">
 <div id="main">
    <div style="display:none" class="error">
      Looks like there was a problem saving the test object. Make sure you've set your application ID and javascript key correctly in the call to <code>
Parse.initialize</code> in this file.
    </div>

      </div>

  <script type="text/javascript">
    Parse.initialize("uZXJE7ChTK3XMvs3Nsf8hE5ivHWiGLpEimGAnUp1", "zJ9PQfiin6ZY9FXSqxFvYmuA9uOhsRz64jTWoExL");

var SomeFacts = Parse.Object.extends("SomeFacts");
var theFacts = new SomeFacts();
var supplyInfo = prompt("Enter information:  ");
theFacts.set( "actualInformation" , supplyInfo );
theFacts.save(null, {
  success: function(theFacts) {
    alert('New object created with objectId: ' + theFacts.id);
  },
  error: function(theFacts, error) {
    alert('Failed to create new object, with error code: ' + error.message);
  }
});
}
</script>
</body>
</html>

Full code

[Mod - edited for formatting]

I get this for an error: Failed to load resource: net::ERR_FILE_NOT_FOUND

This is the suspected file: //www.parsecdn.com/js/parse-1.6.7.min.js

<script src="//www.parsecdn.com/js/parse-1.6.7.min.js"></script> should be <script src="http://www.parsecdn.com/js/parse-1.6.7.min.js"></script>, particularly if you are previewing the page as a local file, not through a web server. Leaving off the protocol means the browser will use the same protocol to fetch the link as was used to fetch the page, which is file: not http: when previewing locally.

Also, two other things to note:

  1. you have an extra brace at the end of your script. That will cause a syntax error when you reach it.
  2. that

<center><b><i><u><h1><font color="green">...</h1></u></i></b></center></font>

a. shouldn't be wrapped around the head it should be in the body if at all, b. isn't closed in the correct order (</font> is in the wrong place), c. is better off replaced by CSS styling on an h1.

Okay. But we have updated the code to the http: link and yet it is not working

And now apparently it has the error as: Uncaught TypeError: Parse.Object.extends is not a function

Thank you for your patience sir

Check the Parse docs and see if extends() is really the name of the function you're looking for.

Okay, thanks.

Thank you so much!