CodeFizz

A Free Learn-To-Code Website

JavaScript Syntax

No search results found.

🡹

alert()

<script>
alert("Hi!");
</script>
Try it »

Meaning and Usage


confirm()

<script>
confirm("Which option?");
</script>
Try it »

Meaning and Usage


prompt()

<script>
prompt("What's your name?","Luigi");
</script>
Try it »

Meaning and Usage


var =

<script>
var text="Text!";
text="New text.";
var number=7;
var boolean=true;
var array=["Value 1",2,false];
</script>
Try it »

Meaning and Usage


function(){}

<script>
function message(text){
alert(text);
}
message("This is using a function!");
</script>
Try it »

Meaning and Usage


if, else, and else if

<script>
var name=prompt("What's your name?");
if (name=="Hop"){
alert("We have the same name!");
} else if (name=="Hip"){
alert("You have the same name as my friend!");
} else {
alert("Your name is not the same as mine or my friend's.");
}
</script>
Try it »

Meaning and Usage


.getElementById()

<p id="boop">Hello world!</p>
<script>
document.getElementById("boop").innerHTML="<h2>Text changed!</h2>";
</script>
Try it »

Meaning and Usage


.getElementsByClassName()

<p class="boop">Hello world!</p>
<p class="boop">Hello world.</p>
<script>
document.getElementsByClassName("boop")[0].innerHTML="<h2>Text changed!</h2>";
</script>
Try it »

Meaning and Usage