You are on page 1of 51

Standard Popup Boxes

• Alert box with text and [OK] button


– Just a message shown in a dialog box:
alert("Some text here");
• Confirmation box
– Contains text, [OK] button and [Cancel] button:

confirm("Are you sure?");


• Prompt box
– Contains text, input field with default value:
prompt ("enter amount", 10);

5
Javascript HTML DOM
• https://www.w3schools.com/tags/tryit.asp?
filename=tryhtml5_input_type_button
Selection statements: if, else, switch 
Iteration statements: while, do, and for
JavaScript if, else, and else if

• https://www.w3schools.com/js/js_if_else.asp
• https://www.tutorialspoint.com/
internet_technologies/javascript.htm
Form Validation
https://
www.w3schools.com/js/tryit.asp?filename=tr
yjs_validation_number

https://www.w3schools.com/js/tryit.asp?
filename=tryjs_validation_js
Accessing Elements
• Access elements via their ID attribute
var elem = document.getElementById("some_id")

• Via the name attribute


var arr = document.getElementsByName("some_name")

• Via tag name


var imgTags = el.getElementsByTagName("img")
– Returns array of descendant <img> elements of
the element "el"

15
• The innerHTML property sets or returns the
HTML content (inner HTML) of an element.
• https://www.w3schools.com/jsref/tryit.asp?fil
ename=tryjs
SCALING
• Math.floor(Math.random() * 10) ; returns a
random integer between 0 and 9
SHIFTING
• Math.floor(Math.random() * 10)+1; returns a
random integer between 0 and 10
https://css-tricks.com/lots-of-ways-to-use-math-
random-in-javascript/
Declaring and allocating array in javascript
• https://fdocuments.in/document/chapter-11-
javascript-arrays-56b6df5556fd7.html
THANK YOU
ARRAYS
 An array is a collection of elements of the same type that are
referenced by a common name.

 Why need to use array type?


 Consider the following issue:

"We have a list of 1000 students marks of an


integer type. If the basic data type (int), is
used, we will declare like the following…"

int  studMark0, studMark1, studMark2, ..., studMark999;


ARRAYS

 Can you imagine how long we have to write the


declaration part by using normal variable
declaration?

int main(void)
{
int studMark1, studMark2, studMark3, studMark4,
…, …, studMark998, stuMark999, studMark1000;


return 0;
}
ARRAYS
 By using an array, we just declare like this,

int  studMark[1000];

 This will reserve 1000 contiguous memory locations for storing the students’
marks.
 Graphically, this can be depicted as in the following figure.
• C enables programmers to break up
a program into segments
commonly known as Functions.
• A function is a block of code that
performs a particular task.
Searching
Repetitive/Iterative
int main()
{
printf("II YEAR FOOD TECHNOLOGY");
return 0;
}
int main()
{
printf( "II YEAR FOOD TECHNOLOGY\n");
printf( "II YEAR FOOD TECHNOLOGY\n");
printf( "II YEAR FOOD TECHNOLOGY\n");
printf( "II YEAR FOOD TECHNOLOGY\n");
printf( "II YEAR FOOD TECHNOLOGY\n");
printf( "II YEAR FOOD TECHNOLOGY\n");
printf( "II YEAR FOOD TECHNOLOGY\n");
printf( "II YEAR FOOD TECHNOLOGY\n");
printf( "II YEAR FOOD TECHNOLOGY\n");
printf( "II YEAR FOOD TECHNOLOGY\n");
return 0;
}
for Loop
int main()
{
int i=0;

for (i = 1; i <= 10; i++)


{
printf( "II YEAR FOOD TECHNOLOGY\n");
}

return 0;
}
int main()
{
int i=0;
for (i = 8; i <= 10; i++)
{
printf( "II YEAR FOOD TECHNOLOGY\n");
}
return 0;
}
int main()
{
int i=0;
for (i = 8; i <10; i++)
{
printf( "II YEAR FOOD TECHNOLOGY\n");
}
return 0;
}
While Loop
int main()
{
// initialization expression
int i = 1;
// test expression
while (i < 5)
{
printf( "II YEAR FOOD TECHNOLOGY\n");
// update expression
i++;
} return 0;
}
OUTPUT
do while loop
int main()
{
    int i = 2; // Initialization expression
  
    do
    {
        // loop body
        printf( “II YEAR FOOD TECHNOLOGY\n");    
  
        // update expression
        i++;
  
    }  while (i < 1);   // test expression
  
    return 0;
}
int main()
{
int i = 2;
// Initialization expression
do
{
// loop body
printf( “II YEAR FOOD TECHNOLOGY\n");
// update expression
i++;
}
while (i < 8);
// test expression
return 0;
}
Print 10 natural numbers
Using For Loop

void main()
{
int i;
for (i=1;i<=10;i++)
{
printf("%d ",i);
}
}

You might also like