[Go to site: main page, start]

0% found this document useful (0 votes)
2 views8 pages

Java Script

The document provides an overview of various JavaScript concepts including the ternary operator, switch statements, alert, confirm, and prompt boxes, as well as functions and variable scopes. It includes syntax examples and practical code snippets for each concept. Additionally, it lists common JavaScript events and how to implement them in HTML.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Java Script

The document provides an overview of various JavaScript concepts including the ternary operator, switch statements, alert, confirm, and prompt boxes, as well as functions and variable scopes. It includes syntax examples and practical code snippets for each concept. Additionally, it lists common JavaScript events and how to implement them in HTML.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

➔ JavaScript Conditional Ternary Operator-:

1. What is ternary Operator-:

Conditions → false ----> statement 2


|
True

Statement

 (condition)? True Statement : False Statement

1. Example-:
Var x = 15;
Var z;
(x > 10) ? z = “True” : z = “false”;
[Link](z);

➔ JavaScript Switch Statement-:

Switch Statement in JavaScript:

Ex-:
switch(expression){
case condition 1: statement(s)
break;
case condition 2: statement(s)
break;
case condition 3: statement(s)
break;
default: statement(s)
}

1. Example-:

Code-:
var day = 1;
switch (day){
case 0:
[Link](“Monday”);
break;
case 1:
[Link](“Tuesday”);
break;
case 2:
[Link](“Wednesday”);
break;
case 3:
[Link](“Monday”);
break;
case 4 :
[Link](“thursday”);
break;

case 5:

[Link](“Friday”);
break;
default:
[Link](“invalid”);
}

Q1. WAP to use switch case find age old , young , child.

➔ JavaScript Alert Box


Example-:
<script>
alert(“hello friend”);
</script>

1. Example-:
<script>
Var a = 10;
Var b = 20;
If(a>b){
alert(“A is Greater” +a);
}
else{
alert(“hello Everybody” +b);
}
</script>
➔ JavaScript Confirm Box

1. Example-:

<script>
confirm(“do you like our Website ?”);
</script>
 Button → ok cancel
| |
True false

2. Example-:

<script>
confirm(“do you like our Website ?”);

alert(a);
</script>

3. Example-:

<script>
confirm(“do you like our Website ?”);

if(a){
alert(“thanks”);
}
else{
alert(“sorry”);
}

</script>
➔ JavaScript Prompt Box
1. Example

<script>
prompt(“what is your Name ?”);
</script>
2. Example

<script>
Var a = prompt(“what is your Name ?”);
[Link](a);
</script>
3. Example

Wap to print merit 1 , 2nd , 3rd , fail.

➔ javaScript Function

1. function Syntax in JavaScript:


code-: function functionName(){  function Definition
Statement

functionName();  Calling a function

1. example-:
<script>
function hello(){
[Link](“hello”);
}
function gautam(){
[Link](“hii gautam”);
hello();
[Link](“<br>”);
hello();
[Link](“<br>”);
hello();
[Link](“<br>”);
gautam();
</script>

→JavaScript Function with Parameters-:

Normal code

---------------------

Example -: Var a = 10;

Var b = 20;

[Link](a + b);

function Code

-----------------------

Example-: function sum( a , b){

[Link](a+b);

Sum(10,90);

Sum(30,30);

1. function Syntax in javaScript:

function functionName(parameter1 , paraameter2){


statement

}
functionName(argument1 , argument2);

2. example-:

<script>
function hello(fname , lname){
[Link](“hello” + fname + lname);
}
hello(“gautam” , “singh”);
</script>
3. example-:

<script>
function hello(fname , lname){
[Link](“hello” + fname + lname + “<br>”);
}
hello(“gautam” , “singh”);
</script>
➔ JavaScript Function with Return Value

Function syntax in JavaScript:

Code-:

function functionName(parameter1 , parameter2){

Statements

Return value

Var a functionName(argument1 , argument2);

1. Example-:

<script>
function fullname(fname = “sonu” , lname = “singh”){
var a = fname + “ - “ + lname;
return a;
}
var fn = fullname(“gautam” , “singh”);
[Link](fn);
</script>
2. Example-:

<script>
function add(science , English, math){
var a = science + English + math;
return a;
}
function percentage(tt){
var per = tt/300 *100;
[Link](per);
}
var fn = add(44,53,66);
percentage(total);

[Link](fn);
</script>
➔ JavaScript Global & Local Variable-:

1. Global & Local Variable in JavaScript-:

Var a =10;  Global Variable


Function functionName(){
Var b = 25;  Local Variable
}

CODE-:

<script>

function hello(){

var a = “gautam singh”; → local variable

[Link](a + “<br>”);

hello();

[Link](a); // console error

</script>

CODE-:

<script>

Var a = “gautam singh”);

function hello(){

var a = “gautam singh”; → local variable

[Link](a + “<br>”);

hello();

[Link](a);
</script>

➔ JavaSccript Events

• Click (onClick)
• Double click (ondblclick)
• Right click (oncontextmenu)
• Mouse Hover (onmouseenter)
• Mouse Out (onmouseout)
• Mouse Down (onmousedown)
• Mouse Up (onmouseup)

• Key press (onkeypress)


• Key Up (onkeyup)
• Load (onload)
• Unload (onunload)
• Resize (onresize)
• Scroll (onscroll)

1. Code-:

<!DOCTYPE html>

<html>

<head>

<title> JavaScript</title>

<script>

function hello(){

alert(“hello good morning”);

</script>

</head>

<body (or) (or) >

<button here</button>

<p me</p>

<p me</p>

<p me</p>

<p me</p>

<p me</p>


<p me</p>

<p >click me</p>

<p me</p>

<p me</p>

</body>

You might also like