GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

Test your skills: Variables

Learnwebdevelopment/Core/Scripting/Math

Learn_web_development/Core/Scripting/Math

The aim of this skill test is to help you assess whether you've understood our [Storing the information you need — Variables](/docs/Learn_web_development/Core/Scripting/Variables) article.

> [!NOTE]
> To get help, read our [Test your skills](/docs/Learn_web_development#test_your_skills) usage guide. You can also reach out to us using one of our [communication channels](/docs/MDN/Community/Communication_channels).

## Interactive challenge

First of all, we are giving you a fun, interactive variables challenge created by our [learning partner](/docs/MDN/Writing_guidelines/Learning_content#partner_links_and_embeds), [Scrimba](https://scrimba.com/home).

Watch the embedded scrim, and complete the task on the timeline (the little ghost icon) by following the instructions and editing the code. When you are done, you can resume watching the scrim to check how the teacher's solution matches up with yours.

<mdn-scrim-inline url="https://scrimba.com/learn-javascript-c0v/~011" scrimtitle="Variables practice" survey="true"></scrim-inline>

## Variables 1

To complete this task, add a new line to correct the value stored in the existing `myName` variable to your own name.

<!-- Code shared across examples -->

```html hidden live-sample___variables-1 live-sample___variables-2 live-sample___variables-1-finish live-sample___variables-2-finish
<section></section>
```

```css hidden live-sample___variables-1 live-sample___variables-2 live-sample___variables-1-finish live-sample___variables-2-finish
* {
box-sizing: border-box;
}

p {
color: purple;
margin: 0.5em 0;
}
```

<!-- Example-specific code -->

The starting point of the task looks like this:

100%

Here's the underlying code for this starting point:

```js live-sample___variables-1
let myName = "Paul";

// Don't edit the code above here!

// Add your code here

// Don't edit the code below here!

const section = document.querySelector("section");
const para = document.createElement("p");
para.textContent = myName;
section.appendChild(para);
```

The updated output should look like this:

100%

<details>
<summary>Click here to show the solution</summary>

Your finished JavaScript should look something like this:

```js
// ...
// Don't edit the code above here!

myName = "Chris";

// Don't edit the code below here!
// ...
```

```js hidden live-sample___variables-1-finish
let myName = "Paul";

myName = "Chris";

const section = document.querySelector("section");
const para = document.createElement("p");
para.textContent = myName;
section.appendChild(para);
```

</details>

## Variables 2

The final task for now — in this case you are provided with some existing code, which has two errors present in it. The results panel should be outputting the name `Chris`, and a statement about how old Chris will be in 20 years' time. We want you to fix the problem and correct the output.

The starting point of the task looks like this (nothing is shown yet):

100%

Here's the underlying code for this starting point:

```js live-sample___variables-2
// Fix the following code

const myName = "Default";
myName = "Chris";

let myAge = "42";

// Don't edit the code below here!

const section = document.querySelector("section");
const para1 = document.createElement("p");
const para2 = document.createElement("p");
para1.textContent = myName;
para2.textContent = `In 20 years, I will be ${myAge + 20}`;
section.appendChild(para1);
section.appendChild(para2);
```

The updated output should look like this:

100%

<details>
<summary>Click here to show the solution</summary>

Your finished JavaScript should look something like this:

```js
// Turn the const into a let, so the value can be changed
let myName = "Default";
myName = "Chris";

// myAge needs to have a number datatype
let myAge = 42;

// Don't edit the code below here!
// ...
```

```js hidden live-sample___variables-2-finish
let myName = "Default";
myName = "Chris";
let myAge = 42;

const section = document.querySelector("section");
const para1 = document.createElement("p");
const para2 = document.createElement("p");
para1.textContent = myName;
para2.textContent = `In 20 years, I will be ${myAge + 20}`;
section.appendChild(para1);
section.appendChild(para2);
```

</details>

## See also

Check out [Practice time - Part 3: let and const](https://scrimba.com/learn-javascript-c0v/~059?via=mdn) <sup>[_MDN learning partner_](/docs/MDN/Writing_guidelines/Learning_content#partner_links_and_embeds)</sup> from Scrimba: An interactive challenge providing multiple tests concerning `let` and `const`.

Learn_web_development/Core/Scripting/Math

source: MDN Web Docs mirror · page

Cite this

"Test your skills: Variables". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/Test_your_skills/Variables

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·