Saturday, May 4, 2024

JavaScript Array length and tostring and join Method

JavaScript Array length

<!DOCTYPE html>

<html>

<body>

<h1>JavaScript Arrays</h1>

<h2>The length Property</h2>


<p>The length property returns the length of an array:</p>


<p id="demo"></p>


<script>

const fruits = ["Banana", "Orange", "Apple", "Mango"];

let size = fruits.length;

document.getElementById("demo").innerHTML = size;

</script>


</body>                                                                                 *+


<p>The toString() method returns an array as a comma separated string:</p>

<p id="demo"></p>

<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.toString();
</script>

</body>
</html>

JavaScript Array join()

    <!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The join() Method</h2>

<p>The join() method joins array elements into a string.</p>
<p>It this example we have used " * " as a separator between the elements:</p>

<p id="demo"></p>

<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.join(" * ");
</script>

</body>
</html>
                                                                                                                                            

Wednesday, April 24, 2024

JavaScript Break and Continue

JavaScript Break statement

 <!DOCTYPE html>

<html>

<body>


<h2>JavaScript Loops</h2>


<p>A loop with a <b>break</b> statement.</p>


<p id="demo"></p>


<script>

let text = "";

for (let i = 0; i < 10; i++) {

  if (i === 3) { break; }

  text += "The number is " + i + "<br>";

}


document.getElementById("demo").innerHTML = text;

</script>


</body>

</html>

JavaScript  Continue statement
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Loops</h2>

<p>A loop with a <b>continue</b> statement.</p>

<p>A loop which will skip the step where i = 3.</p>

<p id="demo"></p>

<script>
let text = "";
for (let i = 0; i < 10; i++) {
  if (i === 3) { continue; }
  text += "The number is " + i + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>

Monday, June 26, 2023

JavaScript Data

 

JavaScript Date Objects

JavaScript Date Objects let us work with dates:

Mon Jun 26 2023 11:26:10 GMT-0700 (Pacific Daylight Time)

Examples

<!DOCTYPE html>

<html>

<body>


<h1>JavaScript Dates</h1>

<h2>Using new Date()</h2>

<p>new Date() without arguments, creates a date object with the current date and time:</p>


<p id="demo"></p>


<script>

const d = new Date();

document.getElementById("demo").innerHTML = d;

</script>


</body>

</html>

Creating Date Objects

Date objects are created with the new Date() constructor.

There are 9 ways to create a new date object:

new Date()
new Date(date string)

new Date(year,month)
new Date(year,month,day)
new Date(year,month,day,hours)
new Date(year,month,day,hours,minutes)
new Date(year,month,day,hours,minutes,seconds)
new Date(year,month,day,hours,minutes,seconds,ms)

new Date(milliseconds)


JavaScript Animated

  JavaScript Animated <!DOCTYPE html> <html> <style> #myContainer {   width: 400px;   height: 400px;   position: relative;...