0% found this document useful (0 votes)
11 views1 page

JavaScript Variables Example Code

The document contains HTML and JavaScript code that demonstrates the use of variables in JavaScript. It includes a simple HTML structure with a linked JavaScript file that defines a string, number, boolean, and object, then displays these values on the webpage. The example showcases how to manipulate the DOM to show the defined variables in a designated output area.

Uploaded by

anitajohn123789
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

JavaScript Variables Example Code

The document contains HTML and JavaScript code that demonstrates the use of variables in JavaScript. It includes a simple HTML structure with a linked JavaScript file that defines a string, number, boolean, and object, then displays these values on the webpage. The example showcases how to manipulate the DOM to show the defined variables in a designated output area.

Uploaded by

anitajohn123789
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

HTML and JavaScript Code

HTML Code ([Link])

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Variables</title>
<!-- Link to external JavaScript file -->
<script src="[Link]" defer></script>
</head>
<body>
<h1>JavaScript Variables Example</h1>

<div id="output"></div> <!-- This is where the output will be displayed -->
</body>
</html>

JavaScript Code ([Link])

// 1. A string with your name


const name = "ChatGPT";

// 2. A number representing your age


const age = 3; // (since ChatGPT launched in 2020)

// 3. A boolean indicating whether you like JavaScript


const likesJavaScript = true;

// 4. An object representing a car with properties: make, model, and year


const car = {
make: "Toyota",
model: "Corolla",
year: 2022
};

// Displaying the values on the page


const outputDiv = [Link]('output');
[Link] = `
<p>Name: ${name}</p>
<p>Age: ${age}</p>
<p>Likes JavaScript: ${likesJavaScript}</p>
<p>Car Details: ${[Link]} ${[Link]}, ${[Link]}</p>
`;

You might also like