JavaScript Basics Worksheet
JavaScript Basics Worksheet
1. What is JavaScript?
JavaScript is the programming language of the web. It allows you to make your web pages interactive and
dynamic.
2. Variables
Variables store data values. You can use 'let', 'const', or 'var' to declare variables.
3. Loops
Loops are used to repeat code. Two common loops are 'for' and 'while'.
Practice:
4. Functions
function greet(name) {
return "Hello, " + name;
}
Arrow Function:
const greet = (name) => "Hello, " + name;
JavaScript Basics: Variables, Loops, and Functions
Challenge:
function isEven(num) {
return num % 2 === 0;
}
You can use JavaScript to interact with HTML elements like this:
<script>
function sayHello() {
const name = document.getElementById("nameInput").value;
alert("Hello " + name + "!");
}
</script>
Homework:
2. Display a greeting.