Java Script

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

JavaScript

Saturday, 27 January 2024 11:35

Needed to allow interaction with


the website

Conditionals - identical to C syntax

Variables -
Key word let

Let counter = 0

Counter++; is back in javascript

Loops in javascript

SAME AS C but let instead of int


SAME AS C but let instead of int

While(true)
{
}

Javascript allows us to dynamically


manipulate and change data, nodes
in memory to display on a website
Can be executed client side on the
browser

Events that you can listen for in


javascript to update user experience

<form onsubmit=" JAVASCRIPT


CODE">

Greeting function in javascript -

function greet()
{
Greeting function in javascript -

function greet()
{
alert('hello,
world');
}

Should be seperated into different


files

As it reads top to bottom , if u need


to wait till everything has loaded
You can add -
Document.addEventListener('DOMC
ontentLoaded', function () {add
script here}

<!DOCTYPE html>
<html lang="en">
<head>
<script>

document.addEventListener('DOM
ContentLoaded', function(){

document.querySelector('form')
.addEventListener('submit',
function() {
let name =
document.querySelector('#name'
).value;

alert('hello, ' + name);

event.preventDefault()
});
});

</script>
<title>
hello, title
</title>
});
});

</script>
<title>
hello, title
</title>
</head>
<body>
<form
onsubmit="greet(); return
false">
<input
autocomplete="off" autofocus
id="name" placeholder="name"
type="text">
<button
type="submit">Greet</button>
</form>
</body>
</html>

PLACING JAVASCRIPT IN A
SEPARATE FILE
-

<script>
src="hello.js"</script>

You might also like