Problems with Javascript and CodePen

I’m working on the Random Quote Challenge and ran into a problem I cannot resolve, so I need some other pair of eyes identifying what I miss.

I want to use the function when clicking on a button, right now there is only the twitter button implemented. For test purposes, it’s supposed to open a German news page ( to start with. But when I click the button nothing happns.

You can find the code here:

Trying to nail the error down I created a new pen. As far as I see it every relevant part is copied there. But in this pen,clicking the button opens the page as intended:

Does anybody of you see why it doesn’t work in the fist pen but does in the second?

Thank you.

1 Like

I narrowed it down to the HTML code, but can not figure it out either. I will keep trying.


Thanks for the hint. Didn’t imagine the HTML could be a problem…

1 Like

I figured what was causing the problem and I was correct about it being in the html section.

In the last line of your html (see below), you started a comment, but did not close it with -->.

<!-- class ="container">

When you opened that last comment but did not close it, it caused a problem for the way Codepen inserts other code behind the scenes for you. Codepen automatically inserts all the external scripts and your JS module section at the end of your html section, so when everything is put together and shown in the preview window, your code looks like the code below. Notice how starting at the <script> tags near the bottom, everything is commented out? This caused the JavaScript not to work.

<!DOCTYPE html>
<html lang="en" >
  <meta charset="UTF-8">
  <title>The Quotes Machine</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="//"/>
  <link href="|Lobster" rel="stylesheet"> 
  <link rel='stylesheet prefetch' href=''>
  <link rel="stylesheet" href="css/style.css"> 

  <div class="container">
    <div class="row" id="headline-row">
      <div class="col">
        <h1 class="text-center" id="headline">The Quotes Machine</h1>
    </div> <!-- row-->
    <div class="row align-items-center" id="quotes-row"> 
      <div class="col">
        <div id="quotes-box"class="text-center">
          <p id="quote">Quotes go here</p>
          <p id="author" class="text-right">Authors go here</p>
    <div class="row" id="buttons-row">
      <div class="col-sm-7">
        <div id="button-box">
          <div class="social-buttons">
              <button class="btn btn-info" title="Tweet it" id="tweetbutton" target="_blank"><i class="fa fa-twitter"></i></button>
            <button class="btn btn-info" title="Share on"><img src="" alt=" Icon" height="20em"></button>
            <button class="btn btn-info" title="Share on Hubzilla"><i class=" hublogo-hubs"></i></button>
        </div><!-- button-box -->
      </div><!-- column -->
      <div class="col-sm-5">
        <button id="newquote" class="btn btn-primary" title="New Quote">New Quote</button>
    </div><!-- row end -->
  </div><!-- class ="container">
  <script src=''></script>
  <script src=''></script>
  <script src=''></script>
  <script  src="js/index.js"></script>

Thank you for finding out! What a stupid typo! I would have been searching forever I’m afraid.

1 Like