Tutorialspoint

Odd numbers summation using javascript

<html>
<body>
<script>
var tot = 0;
var a = [1,45,78,9,78,40,67,76];
for(var i = 0; i<a.length;i++){
if(a[i]%2 !== 0){
tot += a[i]
}
}
document.write(tot);
</script>
</body>
</html>

javascript Date() object

<html>
<body>
<script>
var d = new Date(2019, 9, 19);
document.write(d);
</script>
</body>
</html>

Date() object to get time with milli seconds in javascript

<html>
<body>
<script>
var d = new Date(2019, 9, 19, 5, 33, 30, 0);
document.write(d);
</script>
</body>
</html>

Simple date() object in javascript

<html>
<body>
<script>
var d = new Date();
document.write(d);
</script>
</body>
</html>

shift() in javascript

<html>
<body>
<p id="shift"></p>
<script>
var a = [1,2,3,4,5];
var b = ["apple","mango","banana","guava","strawberry"]
a.shift();
b.shift();
document.write(a);
document.getElementById("shift").innerHTML = b;
</script>
</body>
</html>

Adding element to javascript object

<html>
<body>
<p id="demo"></p>
<script>
var car = {name:"Benz", "Brand": "Mercedes", model:"open roof"};
car.price = "50,000$",
car.color = "Black"
//console.log(car);
document.write(JSON.stringify(car));
</script>
</body>
</html>

output through alert box in javascript

<html>
<body>
<script>
alert(2 + 3);
</script>
</body>
</html>

output through console.log in javascript

<html>
<body>
<script>
console.log(2 + 3);
</script>
</body>
</html>

output through document.write() in javascript

<html>
<body>
<script>
document.write(2 + 3);
</script>
</body>
</html>

displaying output through id attribute in javascript

<html>
<body>
<p id="display"></p>
<script>
document.getElementById("display").innerHTML = 10 + 10;
</script>
</body>
</html>

1 2 3 4 5 6 7 ... 8377 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.