Code from exercise doesn't work outside of codecademy


Exercise 5. I tried using this code outside of codecademy however when i click the post button it doesn't post/clear the text from the 'status-box.' also wasn't updating counter but I have taken that out. I think it isn't linking to my javascript file correctly. Ty in advance to anyone who takes a look.

In my html:
 <div class="col-sm-3">
      <ul class="posts">
        <div class="form-group">
          <textarea class="form-control status-box" rows="1" placeholder="What's on your mind?"></textarea>
        <div class="button-group">
          <a href="#" class="btn btn-primary">
          <img src="" width="30" height="30">
      <script src="//"></script>
 	   <script src="app.js"></script>

In my javascript:
var main = function() {
    $('.btn').click(function() {
    var post = $('.status-box').val();



Hi Cioudyy,

<script src="//"></script>

Change that line to:

<script src=""></script>

instead, and your code will work :slight_smile:

The reason it doesn't work locally right now is because // is what's called a protocol relative URL. This means that if you access your website over HTTPS, it will fetch the resource over HTTPS, and if you visit via HTTP, the resource will be delivered via HTTP. And if you visit your website with the file protocol (file://...), then it will try to fetch the resource via file. The problem is, the file protocol is for viewing local files stored on your computer only, you can't use it to fetch resources from a remote server. So you need to use HTTP(S) instead :slight_smile:

Protocol relative URLs were a good idea a few years ago, but should not be used anymore due to various reasons.


This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.