HTML Practical 13.2 - 13.4 | 2nd to 4th | Web-Programming | WebDevs I CS

The Combine Website of all Practicals till 1 to 15 will upload Soon !!!






HTML Practical 13 (2nd to 4th)| Web-Programming | WebDevs I CS


2). Functions

JavaScript functions are used to perform operations. We can call JavaScript function many times to reuse the code.

Syntax:
function functionName([arg1, arg2, ...argN])
{  
 //code to be executed  
}
  
    <html>
<body>
<script>  
function msg(){  
alert("hello! this is message");  
}  
</script>  
<input type="button" onclick="msg()" value="call function"/>  
</body>
</html>  


    <html>
<body>
<script>  
function getcube(number){  
alert(number*number*number);  
}  
</script>  
<form>  
<input type="button" value="click" onclick="getcube(4)"/>  
</form>  
</body>
</html>



    <html>
<body>
<script>
var add=new Function("num1","num2","return num1+num2");
document.writeln(add(2,5));
</script>
</body>
</html>



3. JavaScript Boolean

Boolean is a datatype that returns either of two values i.e. true or false.

Syntax:
Boolean(variable/expression)
    <html>
<body>
<h2>JavaScript Booleans</h2>
<script>
document.write(Boolean(10 > 9));
</script>
</body>
</html>


4. Math

The JavaScript Math object allows you to perform mathematical tasks on numbers.

Syntax:
Math.property.

    <html>
<body>
<script>
document.write(Math.PI);
</script>
</body>
</html>



    <html>
<body>
<script>
document.write
("<p><b>Math.E:</b> " + Math.E + "</p>" +
"<p><b>Math.PI:</b> " + Math.PI + "</p>" +
"<p><b>Math.SQRT2:</b> " + Math.SQRT2 + "</p>" +
"<p><b>Math.SQRT1_2:</b> " + Math.SQRT1_2 + "</p>" +
"<p><b>Math.LN2:</b> " + Math.LN2 + "</p>" +
"<p><b>Math.LN10:</b> " + Math.LN10 + "</p>" +
"<p><b>Math.LOG2E:</b> " + Math.LOG2E + "</p>" +
"<p><b>Math.Log10E:</b> " + Math.LOG10E + "</p>");
</script>
</body>
</html>



➪Math methods():

i. Math.round()

    <html>
<body>
<script>
document.write(Math.round(4.6));
</script>
</body>
</html>

ii. Math.ceil()

    
<html>
<body>
<script>
document.write(Math.ceil(4.4));
</script>
</body>
</html>



iii. Math.floor()

    
<html>
<body>
<script>
document.write(Math.floor(4.7));
</script>
</body>
</html>
<html>
<body>
<script>
document.write(Math.floor(4.7));
</script>
</body>
</html>




iv. Math.trunc()

    
<html>
<body>
<script>
document.write(Math.trunc(4.7));
</script>
</body>
</html>




Post a Comment

Previous Post Next Post