PythonIntermediate PythonNumPySQLGen AI
HTMLCSSJavaScriptIntermediate JavaScriptReactp5.jsNode.js
Command LineGit & GitHub
C++JavaData Structures & Algorithms

Exercise

06. Band Tour |

A New Way to JavaScript

Let's dig into exactly how React code is written.

let header = <header>Compiler Coffee ☕</header>;

This is JSX. It looks like a mashup of HTML and JavaScript!

Meme of JavaScript disguised as HTML

Sometimes referred to as "JavaScript Syntax Extension", parts of JSX are disguised as HTML. When you run a React app, the HTML-like parts are transpiled into browser-readable JavaScript!

With JSX, you can write the HTML tags you know and love such as <header>, <div>, or <p>.

JSX can also be written as a function that returns markup:

function addHeading() {
  return (
    <div>
      <header>Compiler Coffee ☕</header>
      <p>Our coffee is home brewed!</p>
    </div>
  )
}

We can see the power of React as we use a function to return our website's markup!

JSX is only valid if everything is wrapped under a single element:

// Incorrect
return (
  <h1>The Outsiders</h1>
  <p>by S.E. Hinton</p>
)

// Correct
return (
  <div>
    <h1>The Outsiders</h1>
    <p>by S.E. Hinton</p>
  </div>
)

As you progress through this chapter, you will start to realize how powerful writing with JSX is when building websites.

Instructions

Your friend's band is going on tour and they'd like your help with their website.

Let's create some JSX and a list of tour stops!

First, replace the comment with a <div> element inside the return statement.

Inside the <div>, write a <h1> that reads "Tour Stops".

Then, paste the following below the heading:

<ul>
  <li>🇺🇸 New York City, US - Madison Square Garden</li>
  <li>🇬🇧 London, UK - Wembley Stadium</li>
  <li>🇩🇪 Munich, DE - Zenith Halle</li>
  <li>🇯🇵 Tokyo, JP - Budokan</li>
  <li>🇦🇺 Melbourne, AU - The Forum</li>
</ul>

Afterward, turn to the output window on the right. This heading and list should be displayed.

Help

Get a Hint

Want the solution? Try completing the lesson first!

New Item Unlocked!

pom pom characters gifitem duck

Rubber Duck NEW

Rubber duck debugging is a classic technique used by developers to debug code. By explaining the code line-by-line to a rubber duck, you can break down the code into smaller pieces, and potentially identify the error.

... It's silly, we know.

New Item Unlocked!

pom pom characters gifitem duck

Codédex BotNEW

I’m a coding mentor bot built with GPT-4 👋. I’m here to answer any questions related to programming, Codédex, and much more.

FEATURE UNLOCKED!

sad characters gif

You have 100 XP! This means you can now join our Discord community to chat and hang out with fellow learners and the team behind Codédex!
See you there. 😊

FEATURE UNLOCKED!

pom pom characters gif

You have 250 XP! This means you can now join our On-Platform community to chat and hang out with fellow learners!
Say hi in the Introductions channel. 😊

export default function App() {
return <div> {/* Write code here 💖 */} </div>;
}

item duck
item duck
user image

Hi, I’m Codédex Bot! I’m a coding mentor bot built with GPT-4 👋.

I’m here to answer any questions related to programming, Codédex, and much more.

For example, try to ask something like:

  • What are classes and objects in Python?
  • How to create a table in HTML?
  • What's if (variable > 2) print(‘greater’)?
  • What's Codédex Club?
send image
user image
send image

First React App

JSX & Components

06. Band Tour

07. Embedded JS

08. Travel Gallery

09. Hot Takes Pt. 1

10. Hot Takes Pt. 2

Props & State

Events

Checkpoint Project

Forms

Hooks

Data Fetching

Routing

06. Band Tour

15 XP

Exercise

06. Band Tour |

A New Way to JavaScript

Let's dig into exactly how React code is written.

let header = <header>Compiler Coffee ☕</header>;

This is JSX. It looks like a mashup of HTML and JavaScript!

Meme of JavaScript disguised as HTML

Sometimes referred to as "JavaScript Syntax Extension", parts of JSX are disguised as HTML. When you run a React app, the HTML-like parts are transpiled into browser-readable JavaScript!

With JSX, you can write the HTML tags you know and love such as <header>, <div>, or <p>.

JSX can also be written as a function that returns markup:

function addHeading() {
  return (
    <div>
      <header>Compiler Coffee ☕</header>
      <p>Our coffee is home brewed!</p>
    </div>
  )
}

We can see the power of React as we use a function to return our website's markup!

JSX is only valid if everything is wrapped under a single element:

// Incorrect
return (
  <h1>The Outsiders</h1>
  <p>by S.E. Hinton</p>
)

// Correct
return (
  <div>
    <h1>The Outsiders</h1>
    <p>by S.E. Hinton</p>
  </div>
)

As you progress through this chapter, you will start to realize how powerful writing with JSX is when building websites.

Instructions

Your friend's band is going on tour and they'd like your help with their website.

Let's create some JSX and a list of tour stops!

First, replace the comment with a <div> element inside the return statement.

Inside the <div>, write a <h1> that reads "Tour Stops".

Then, paste the following below the heading:

<ul>
  <li>🇺🇸 New York City, US - Madison Square Garden</li>
  <li>🇬🇧 London, UK - Wembley Stadium</li>
  <li>🇩🇪 Munich, DE - Zenith Halle</li>
  <li>🇯🇵 Tokyo, JP - Budokan</li>
  <li>🇦🇺 Melbourne, AU - The Forum</li>
</ul>

Afterward, turn to the output window on the right. This heading and list should be displayed.

Help

Get a Hint

FEATURE UNLOCKED!

sad characters gif

You have 100 XP! This means you can now join our Discord community to chat and hang out with fellow learners and the team behind Codédex!
See you there. 😊

FEATURE UNLOCKED!

pom pom characters gif

You have 250 XP! This means you can now join our On-Platform community to chat and hang out with fellow learners!
Say hi in the Introductions channel. 😊

export default function App() {
  return <div> 
{/* Write code here 💖 */} </div>; }