KEMBAR78
Java script – basic auroskills (2) | PPTX
JAVASCRIPT – BASIC –
AUROSKILLS
Content
Tables Of Content:-
1.1What Is Javascript?
1.2 JavascriptVariables
1.3 Functions
1.4 JavascriptVariable Scope
1.5 If Else Loop
1.6 Switch Case
1.7While-Loop
1.8 Do-while loop
1.9 For Loop
1.10 Factorial of a number
1.10.1 Factorial Approach
1.10.2 Recursive Approach
2.0 Fibonacci Series
Assignment :-
Assignment No:-1 Display Hello world
Assignment No:-2 HelloWorld In Head
Assignment no :-3 StoringValues InVariables and
Print It
Assignment no:-04 Declare Global And Local
Variables
Assignment no:-05 If Statement
Assignment no:-06 If Else Statement
Assignment no:-07 If Else If
Assignment no:-08 Switch Case
Assignment no:-09 While loop
Assignment no:-10 Do - While
Assignment no:-11 For-Loop
Assignment no:-12 IterativeApproach In Factorial
Assignment no:-13 Factorial Recursive Approach
Assignment no:-14 Recursion in Fibonanci Series
Assignment no:-15 Fibonanci Series
Task:-
1.0Task No:-1
2.0Task No:-2
3.0Task No:-3
4.0Task No:-4
5.0Task No:-5
6.0Task No:-6
7.0Task No:-7
1.1 What is JavaScript?
JavaScript is a dynamic computer programming language. It is lightweight and
most commonly used as a part of web pages, whose implementations allow client-
side script to interact with the user and make dynamic pages. It is an interpreted
programming language with object-oriented capabilities.
Build In 1995.
Designed for creating network-centric applications
Complementary to and integrated with Java
Complementary to and integrated with Java
Assignment No:-1
• Display “Hello World”.
<html>
<body>
<Script>
document.write(“Hello World”);
</script>
</body>
</html>
TASK NO:-01
• “Hello World” In console.log
• “Hello World” In document.getelementbyID()
Assignment No:-2
• Display “Hello World”.in Head
<html>
<head>
<script>
document.write(“Hello World”);
</script>
</head>
TASK NO:-02
• Use Console & ID to Print Hello World In Head part.
1.2 JavaScriptVariables:-
• Like many other programming languages, JavaScript has variables.Variables can be
thought of as named containers.You can place data into these containers and then refer
to the data simply by naming the container.
<script>
var money;
var name;
</script>
Assignment no :-3
• StoringValue inVariable And Print it
<script>
var name = “Boney”;
var money;
money = 2000;
Document.write(name);
Console.log(money) ;
</script>
1.3 Functions
• Functions are the main “building blocks” of the program.They allow the code to be called many times without repetition.
<script>
function showMessage()
{
alert( 'Hello everyone!’ );
}
showMessage();
</script>
1.4 JavaScriptVariable Scope
The scope of a variable is the region of your program in which it is defined.
JavaScript variables have only two scopes
• GlobalVariables: A global variable has global scope which means it can be
defined anywhere in your JavaScript code.
• LocalVariables: A local variable will be visible only within a function where
it is defined. Function parameters are always local to that function.
Assignment no:-04
• Declare Global And LocalVariable
<script>
var myVar=“global”;
function checkscope()
{
var myVar=“Local”;
document.write(myVar);
}
</script>
Task No :- 03
• Declare Add, Multiply & Divide in Function
• Then Declare one thing add , multiply or divide in global or local variable
1.5 If Else Loop:-
While writing a program, there may be a situation when you need to adopt one out of a
given set of paths. In such cases, you need to use conditional statements that allow your
program to make correct decisions and perform right actions.
JavaScript supports the following forms of if..else statement:
1) if statement
2) if...else statement
3) if...else if... Statement
if Statement :-The ‘if’ statement is the fundamental control statement that allows
JavaScript to make decisions and execute statements conditionally.
Assignment no:-05
• If Statement
<body>
<script>
var age = 20;
If (age > 18)
{
document.write(“<b>Qualify for driving</b>”);
}
</script>
</body>
Assignment no:-06
• If Else Statement:-
<script>
var age = 15 ;
If ( age > 18 )
{
document.write(“ qualify for driving”);
}
else
{
document.write(“Does not Qualify for Driving”);
}
</script>
Assignment no:-07
• if...else if... Statement
<script>
var book = “maths”;
If ( book == “history” )
{
document.write(“history book”);
}
else if (book == “maths” )
{
document.write(“book found”);
}
else
{
document.write(“Unkown book”);
}
</script>
Task No :- 04
• Perform different Output for
• If statement
• If else
• Else if
1.6 Switch-Case
• You can use multiple if...else…if statements, to perform a multiway branch.
However, this is not always the best solution, especially when all of the branches
depend on the value of a single variable.
• you can use a switch statement which handles exactly this situation, and it does so
more efficiently than repeated if...else if statements.
Switch-Case Syntax:-
switch (expression)
{
case condition 1: statement(s)
break;
case condition 2: statement(s)
break;
...
case condition n: statement(s)
break;
default: statement(s)
}
Assignment no:-08
• Switch-Case
<script>
var grade='A';
document.write("Entering switch block<br />");
switch (grade)
{
case 'A': document.write("Good job<br />");
break;
case 'B': document.write("Pretty good<br />");
break;
case 'C': document.write("Passed<br />");
break;
default: document.write("Unknown grade<br />")
}document.write("Exiting switch block");
</script>
1.7 While-Loop:-
• While writing a program, you may encounter a situation where you need to
perform an action over and over again. In such situations, you would need to write
loop statements to reduce the number of lines.
• The purpose of a while loop is to execute a statement or code block repeatedly as
long as an expression is true.
While-Loop syntax:-
while (expression)
{
Statement(s) to be executed if expression is true
}
Assignment no:-09
• While-Loop:-
<script >
var count = 0;
document.write("Starting Loop ");
while (count < 10)
{
document.write("CurrentCount : " + count + "<br />");
count++;
}
document.write("Loop stopped!");
</script>
1.8 Do-While-Loop:-
• The do...while loop is similar to the while loop except that the condition check
happens at the end of the loop.This means that the loop will always be executed
at least once, even if the condition is false.
Do-While-loop Syntax:-
Do
{
Statement(s) to be executed;
} while (expression);
Assignment no:-10
• Do-While
<script >
var count = 0;
document.write("Starting Loop" + "<br />");
Do
{
document.write("Current Count : " + count + "<br />");
count++;
}
while (count < 5);
document.write ("Loop stopped!");
</script>
Task No :- 05
• Perform task for
• Switch-case
• While loop
• Do while
1.9 For Loop:-
The ‘for’ loop is the most compact form of looping. It includes the following three
important parts:
1.The loop initialization where we initialize our counter to a starting value.The
initialization statement is executed before the loop begins.
2.The test statement which will test if a given condition is true or not. If the
condition is true, then the code given inside the loop will be executed, otherwise the
control will come out of the loop.
3.The iteration statement where you can increase or decrease your counter.
For-Loop Syntax:-
for (initialization; test condition; iteration statement)
{
Statement(s) to be executed if test condition is true
}
Assignment no:-11
• For-loop:-
<script type="text/javascript">
var count;
document.write("Starting Loop" + "<br />");
for(count = 0; count < 10; count++){
document.write("Current Count : " + count );
document.write("<br />");
}
document.write("Loop stopped!");
</script>
Task no:-06
• Perform task for for-loop.
• Use for and while loop in a single format.
• Use for and if loop in a single format.
1.10 Factorial Of a Number:-
Factorial of number is the product of all positive descending integers. Factorial of n
is denoted by n!. For example -
4! = 4 * 3 * 2 * 1 = 24
5! = 5 * 4 * 3 * 2 * 1 = 120
Formulas:-
factorial(n)=n∗(n−1)∗...∗1
factorial(n)=n∗factorial(n−1)
1.10.1 Factorial Approach:-
There are two ways to compute the factorial of a number in JavaScript.
• Iterative
• Recursive
1.The iterative approach
Keeping in mind the first definition of a factorial, the variable i is initially set equal to n and
is gradually decremented to 1. In each step, the result of the multiplication is stored in the
variable answer.
Assignment no:-12
• Iterative-Approach in Factorial :-
function factorial(n){
let answer = 1;
if (n == 0 || n == 1){
return answer;
}else{
for(var i = n; i >= 1; i--){
answer = answer * i;
} return answer;
}
}
let n = 4;
answer = factorial(n)
console.log("The factorial of " + n + " is " + answer);
</script>
1.10.2The recursive approach:-
• As stated above, the factorial of n can be found by finding the factorial of a
number one less than n, and then multiplying this answer with n. So the factorial
of n-1 can be thought of as a subproblem that needs to be computed first.
function call return value
factorial(1) 1 (base case)
factorial(2) 2 * 1 = 2
factorial(3) 3 * 2 = 6
factorial(4) 4 * 6 = 24
Assignment no:-13
• Factorial recursive approach:-
function factorial(n)
if(n == 0 || n == 1){
return 1;
//recursive case
}else{
return n * factorial(n-1);
}
}
let n = 4;
answer = factorial(n)
console.log("The factorial of " + n + " is " + answer);
2.0 Fibonacci Series:-
The sequence of Fibonacci numbers has the formula Fn = Fn-1 + Fn-2. In other
words, the next number is a sum of the two preceding ones.
First two numbers are 1, then 2(1+1), then 3(1+2),
5(2+3) and so on: 1, 1, 2, 3, 5, 8, 13, 21……….n
Assignment no:-14
• Recursion in Fibonacci series:-
function fibonacci(n) {
if (n === 1 || n === 0) {
return 1;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
console.log(fibonacci(10));
Assignment no:-15
• Fibonacci series:-
<script>
function fibonancci(n)
{
const arr = [1]
let current = 1;
let previous = 0;
if(n <= 1)
{
return arr
}
while(n>0)
{
current += previous
previous = current - previous
arr.push(current)
n-=1
}
return arr
}
console.log(fibonancci(10));
</script>
Task No:-07
• Print Factorial and Fibonacci series.
• Print Odd and even number
• Print Interment and decrement of a number
• Print A star pyramid.
• Print color in switch case condition.

Java script – basic auroskills (2)

  • 1.
    JAVASCRIPT – BASIC– AUROSKILLS
  • 2.
    Content Tables Of Content:- 1.1WhatIs Javascript? 1.2 JavascriptVariables 1.3 Functions 1.4 JavascriptVariable Scope 1.5 If Else Loop 1.6 Switch Case 1.7While-Loop 1.8 Do-while loop 1.9 For Loop 1.10 Factorial of a number 1.10.1 Factorial Approach 1.10.2 Recursive Approach 2.0 Fibonacci Series Assignment :- Assignment No:-1 Display Hello world Assignment No:-2 HelloWorld In Head Assignment no :-3 StoringValues InVariables and Print It Assignment no:-04 Declare Global And Local Variables Assignment no:-05 If Statement Assignment no:-06 If Else Statement Assignment no:-07 If Else If Assignment no:-08 Switch Case Assignment no:-09 While loop Assignment no:-10 Do - While Assignment no:-11 For-Loop Assignment no:-12 IterativeApproach In Factorial Assignment no:-13 Factorial Recursive Approach Assignment no:-14 Recursion in Fibonanci Series Assignment no:-15 Fibonanci Series Task:- 1.0Task No:-1 2.0Task No:-2 3.0Task No:-3 4.0Task No:-4 5.0Task No:-5 6.0Task No:-6 7.0Task No:-7
  • 3.
    1.1 What isJavaScript? JavaScript is a dynamic computer programming language. It is lightweight and most commonly used as a part of web pages, whose implementations allow client- side script to interact with the user and make dynamic pages. It is an interpreted programming language with object-oriented capabilities. Build In 1995. Designed for creating network-centric applications Complementary to and integrated with Java Complementary to and integrated with Java
  • 4.
    Assignment No:-1 • Display“Hello World”. <html> <body> <Script> document.write(“Hello World”); </script> </body> </html>
  • 5.
    TASK NO:-01 • “HelloWorld” In console.log • “Hello World” In document.getelementbyID()
  • 6.
    Assignment No:-2 • Display“Hello World”.in Head <html> <head> <script> document.write(“Hello World”); </script> </head>
  • 7.
    TASK NO:-02 • UseConsole & ID to Print Hello World In Head part.
  • 8.
    1.2 JavaScriptVariables:- • Likemany other programming languages, JavaScript has variables.Variables can be thought of as named containers.You can place data into these containers and then refer to the data simply by naming the container. <script> var money; var name; </script>
  • 9.
    Assignment no :-3 •StoringValue inVariable And Print it <script> var name = “Boney”; var money; money = 2000; Document.write(name); Console.log(money) ; </script>
  • 10.
    1.3 Functions • Functionsare the main “building blocks” of the program.They allow the code to be called many times without repetition. <script> function showMessage() { alert( 'Hello everyone!’ ); } showMessage(); </script>
  • 11.
    1.4 JavaScriptVariable Scope Thescope of a variable is the region of your program in which it is defined. JavaScript variables have only two scopes • GlobalVariables: A global variable has global scope which means it can be defined anywhere in your JavaScript code. • LocalVariables: A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
  • 12.
    Assignment no:-04 • DeclareGlobal And LocalVariable <script> var myVar=“global”; function checkscope() { var myVar=“Local”; document.write(myVar); } </script>
  • 13.
    Task No :-03 • Declare Add, Multiply & Divide in Function • Then Declare one thing add , multiply or divide in global or local variable
  • 14.
    1.5 If ElseLoop:- While writing a program, there may be a situation when you need to adopt one out of a given set of paths. In such cases, you need to use conditional statements that allow your program to make correct decisions and perform right actions. JavaScript supports the following forms of if..else statement: 1) if statement 2) if...else statement 3) if...else if... Statement if Statement :-The ‘if’ statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally.
  • 15.
    Assignment no:-05 • IfStatement <body> <script> var age = 20; If (age > 18) { document.write(“<b>Qualify for driving</b>”); } </script> </body>
  • 16.
    Assignment no:-06 • IfElse Statement:- <script> var age = 15 ; If ( age > 18 ) { document.write(“ qualify for driving”); } else { document.write(“Does not Qualify for Driving”); } </script>
  • 17.
    Assignment no:-07 • if...elseif... Statement <script> var book = “maths”; If ( book == “history” ) { document.write(“history book”); } else if (book == “maths” ) { document.write(“book found”); } else { document.write(“Unkown book”); } </script>
  • 18.
    Task No :-04 • Perform different Output for • If statement • If else • Else if
  • 19.
    1.6 Switch-Case • Youcan use multiple if...else…if statements, to perform a multiway branch. However, this is not always the best solution, especially when all of the branches depend on the value of a single variable. • you can use a switch statement which handles exactly this situation, and it does so more efficiently than repeated if...else if statements.
  • 20.
    Switch-Case Syntax:- switch (expression) { casecondition 1: statement(s) break; case condition 2: statement(s) break; ... case condition n: statement(s) break; default: statement(s) }
  • 21.
    Assignment no:-08 • Switch-Case <script> vargrade='A'; document.write("Entering switch block<br />"); switch (grade) { case 'A': document.write("Good job<br />"); break; case 'B': document.write("Pretty good<br />"); break; case 'C': document.write("Passed<br />"); break; default: document.write("Unknown grade<br />") }document.write("Exiting switch block"); </script>
  • 22.
    1.7 While-Loop:- • Whilewriting a program, you may encounter a situation where you need to perform an action over and over again. In such situations, you would need to write loop statements to reduce the number of lines. • The purpose of a while loop is to execute a statement or code block repeatedly as long as an expression is true.
  • 23.
    While-Loop syntax:- while (expression) { Statement(s)to be executed if expression is true }
  • 24.
    Assignment no:-09 • While-Loop:- <script> var count = 0; document.write("Starting Loop "); while (count < 10) { document.write("CurrentCount : " + count + "<br />"); count++; } document.write("Loop stopped!"); </script>
  • 25.
    1.8 Do-While-Loop:- • Thedo...while loop is similar to the while loop except that the condition check happens at the end of the loop.This means that the loop will always be executed at least once, even if the condition is false.
  • 26.
    Do-While-loop Syntax:- Do { Statement(s) tobe executed; } while (expression);
  • 27.
    Assignment no:-10 • Do-While <script> var count = 0; document.write("Starting Loop" + "<br />"); Do { document.write("Current Count : " + count + "<br />"); count++; } while (count < 5); document.write ("Loop stopped!"); </script>
  • 28.
    Task No :-05 • Perform task for • Switch-case • While loop • Do while
  • 29.
    1.9 For Loop:- The‘for’ loop is the most compact form of looping. It includes the following three important parts: 1.The loop initialization where we initialize our counter to a starting value.The initialization statement is executed before the loop begins. 2.The test statement which will test if a given condition is true or not. If the condition is true, then the code given inside the loop will be executed, otherwise the control will come out of the loop. 3.The iteration statement where you can increase or decrease your counter.
  • 30.
    For-Loop Syntax:- for (initialization;test condition; iteration statement) { Statement(s) to be executed if test condition is true }
  • 31.
    Assignment no:-11 • For-loop:- <scripttype="text/javascript"> var count; document.write("Starting Loop" + "<br />"); for(count = 0; count < 10; count++){ document.write("Current Count : " + count ); document.write("<br />"); } document.write("Loop stopped!"); </script>
  • 32.
    Task no:-06 • Performtask for for-loop. • Use for and while loop in a single format. • Use for and if loop in a single format.
  • 33.
    1.10 Factorial Ofa Number:- Factorial of number is the product of all positive descending integers. Factorial of n is denoted by n!. For example - 4! = 4 * 3 * 2 * 1 = 24 5! = 5 * 4 * 3 * 2 * 1 = 120 Formulas:- factorial(n)=n∗(n−1)∗...∗1 factorial(n)=n∗factorial(n−1)
  • 34.
    1.10.1 Factorial Approach:- Thereare two ways to compute the factorial of a number in JavaScript. • Iterative • Recursive 1.The iterative approach Keeping in mind the first definition of a factorial, the variable i is initially set equal to n and is gradually decremented to 1. In each step, the result of the multiplication is stored in the variable answer.
  • 35.
    Assignment no:-12 • Iterative-Approachin Factorial :- function factorial(n){ let answer = 1; if (n == 0 || n == 1){ return answer; }else{ for(var i = n; i >= 1; i--){ answer = answer * i; } return answer; } } let n = 4; answer = factorial(n) console.log("The factorial of " + n + " is " + answer); </script>
  • 36.
    1.10.2The recursive approach:- •As stated above, the factorial of n can be found by finding the factorial of a number one less than n, and then multiplying this answer with n. So the factorial of n-1 can be thought of as a subproblem that needs to be computed first. function call return value factorial(1) 1 (base case) factorial(2) 2 * 1 = 2 factorial(3) 3 * 2 = 6 factorial(4) 4 * 6 = 24
  • 37.
    Assignment no:-13 • Factorialrecursive approach:- function factorial(n) if(n == 0 || n == 1){ return 1; //recursive case }else{ return n * factorial(n-1); } } let n = 4; answer = factorial(n) console.log("The factorial of " + n + " is " + answer);
  • 38.
    2.0 Fibonacci Series:- Thesequence of Fibonacci numbers has the formula Fn = Fn-1 + Fn-2. In other words, the next number is a sum of the two preceding ones. First two numbers are 1, then 2(1+1), then 3(1+2), 5(2+3) and so on: 1, 1, 2, 3, 5, 8, 13, 21……….n
  • 39.
    Assignment no:-14 • Recursionin Fibonacci series:- function fibonacci(n) { if (n === 1 || n === 0) { return 1; } else { return fibonacci(n - 1) + fibonacci(n - 2); } } console.log(fibonacci(10));
  • 40.
    Assignment no:-15 • Fibonacciseries:- <script> function fibonancci(n) { const arr = [1] let current = 1; let previous = 0; if(n <= 1) { return arr } while(n>0) { current += previous previous = current - previous arr.push(current) n-=1 } return arr } console.log(fibonancci(10)); </script>
  • 41.
    Task No:-07 • PrintFactorial and Fibonacci series. • Print Odd and even number • Print Interment and decrement of a number • Print A star pyramid. • Print color in switch case condition.