My Challenge: Build a Random Quote Machine

Hi all,

I completed this challenge using create-react-app. Now I have a lot of issues bring it to CodePen:

I accomplished to set up everything correctly so that the React app gets rendered. But now the whole functionality is broken…

Any ideas?

Your code so far

import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";

class Form extends Component {
  constructor(props) {
    this.state = {
      quote: "",
      author: ""
    this.handleMessage = this.handleMessage.bind(this);
    this.getQuote = this.getQuote.bind(this);
    this.createLink = this.createLink.bind(this);


  componentDidMount() {
    const script = document.createElement("script");

    script.src =
    script.async = true;


  getQuote() {
    let newQuote = {};
    let endPoint =
    fetch(endPoint, { cache: "reload" })
      .then(blob => blob.json())
        dataObj =>
          (newQuote["content"] = dataObj[0].content) &&
          (newQuote["author"] = dataObj[0].title)
    return newQuote;

  handleMessage(event) {
    const currentQuote = this.getQuote();
    setTimeout(() => {
        quote: currentQuote.content,
    }, 800);

  createLink() {
    let baseLink =
    let currentQuote = this.state.quote;
    let regex = new RegExp(/(<p>)|(<\/p>)/gi);
    return baseLink + currentQuote.replace(regex, "");

  render() {
    return (
      <div className="quote-box" id="quote-box">
        <h1>Quote Machine</h1>
        <div id="text" dangerouslySetInnerHTML={{ __html: this.state.quote }} />
        <br />
        <p id="author">Autor: {}</p>
        <a className="button" onClick={this.handleMessage} id="new-quote">
          New Quote
        <a className="button" id="tweet-quote" href={this.createLink()}>

class App extends Component {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Quote Machine</h1>
        <p className="App-intro">Let see what the day brings!</p>
        <Form />

export default App;

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.25 Safari/537.36.

Link to the challenge:

This bit is what’s breaking it:

import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";

Those are import statements referring to other code that Codepen doesn’t know about. You need to use another way of getting access to React within Codepen.

Hi @Peritract,

Thanks for your answer. As you can see in Codepen I already removed it from the beginning. And actually everything the UI is being rendered but the functionality is broken.
The code I pasted is the one running on my machine.

Any other ideas?


I opened up console to see the errors and I see two errors here.

Looks like because your api is using http and not https it’s being blocked and that’s why ‘currentQuote’ is undefined.


1 Like

That was the problem!

Thanks @shimphillip!

So lately, rather than sticking with codePen, I’ve been using my hosted dev server on codeAnywhere for my projects. I use create-react-app there, among other things.

Have you simply imported the bundle.js indicated on the project page?