Art of While loop

Learning Outcome

6

Control default browser behavior using preventDefault()

5

Identify and use common mouse,keyboard,form and window events

4

Explain why addEventListener is preferred over onclick

3

Use addEventListener() and removeEventListener() correctly

2

Connect user actions to Javascript using event listeners

1

Explain what browser events are and why they exist

Choose cool, soft colors instead of vibrant colors
Max 6 Points for Summary & Min 4

Key Lessons And Insights Gained From Our Previous Session 

For Loop

Before We Start Coding,Let's Understand The Key Concepts We'll Cover Today

While Loop

Type Conversion Functions

While Loop

Type Conversion Functions

How Do Banks, Restaurants, And Cash Counters Detect Currency Authenticity?

How Do Banks, Restaurants, And Cash Counters Detect Currency Authenticity?

They use currency detector machines with UV lights and other methods to check if money is real

Want A Simple JS Example For A Currency Detector Using A While Loop?

Let's code a basic currency detector using a while loop

How Does While Loop Works?

By using a while loop that executes code as long as the condition is true

START

CONDITION

STATEMENT

END

False

True

How Does While Loop Works?

By using a while loop that executes code as long as the condition is true

If the condition is true, the loop's code block will execute repeatedly

START

CONDITION

STATEMENT

True

How Does While Loop Works?

By using a while loop that executes code as long as the condition is true

If the condition is true, the loop's code block will execute repeatedly

START

CONDITION

STATEMENT

True

How Does While Loop Works?

By using a while loop that executes code as long as the condition is true

If the condition in a while loop is false, the loop terminates and the code block does not execute

START

CONDITION

END

False

Unlocking The Power Of Type Conversion In JS

parseInt()

Converts a string to a integer

parseFloat()

Converts to a decimal number

String()

Converts to a string

Boolean()

Converts to a boolean

Number()

Converts to a number

01

02

03

04

05

Let's Implement A Currency Corrector Using A While Loop

let currency;
let value;
let total = 0;
while(true){
currency=(prompt("Currency is present enter y:"));
if (currency == "y"){
value=parseInt(prompt("Enter the Note amount:"));
if (value  == 10 ||  value == 20 || value == 50 || value == 100 || value == 500){
console.log(value + " Real currency");
total+=value;
}
else{
console.log( "Fake currency");
}
}
else{
break;
}
}
console.log(total);

Here, we initialize the variables `currency` and `value`, and assign a value of zero to the `total`

Let's Implement A Currency Corrector Using A While Loop

let currency;
let value;
let total = 0;
while(true){
currency=(prompt("Currency is present enter y:"));
if (currency == "y"){
value=parseInt(prompt("Enter the Note amount:"));
if (value  == 10 ||  value == 20 || value == 50 || value == 100 || value == 500){
console.log(value + " Real currency");
total+=value;
}
else{
console.log( "Fake currency");
}
}
else{
break;
}
}
console.log(total);

Here the condition is true, it will enter the loop

So, now the loop has started executing, prompting the user to enter 'y' if currency is present and 'n' if not

OUTPUT:

Let's Implement A Currency Corrector Using A While Loop

let currency;
let value;
let total = 0;
while(true){
currency=(prompt("Currency is present enter y:"));
if (currency == "y"){
value=parseInt(prompt("Enter the Note amount:"));
if (value  == 10 ||  value == 20 || value == 50 || value == 100 || value == 500){
console.log(value + " Real currency");
total+=value;
}
else{
console.log( "Fake currency");
}
}
else{
break;
}
}
console.log(total);

If the user enters 'y', it jumps to the 'if' code block

OUTPUT:

Let's Implement A Currency Corrector Using A While Loop

let currency;
let value;
let total = 0;
while(true){
currency=(prompt("Currency is present enter y:"));
if (currency == "y"){
value=parseInt(prompt("Enter the Note amount:"));
if (value  == 10 ||  value == 20 || value == 50 || value == 100 || value == 500){
console.log(value + " Real currency");
total+=value;
}
else{
console.log( "Fake currency");
}
}
else{
break;
}
}
console.log(total);

Here, we take input from the user, asking them to enter the note amount

To convert the input to an integer, we use `parseInt`

We store the user's input in the 'value' variable

Let's Implement A Currency Corrector Using A While Loop

let currency;
let value;
let total = 0;
while(true){
currency=(prompt("Currency is present enter y:"));
if (currency == "y"){
value=parseInt(prompt("Enter the Note amount:"));
if (value  == 10 ||  value == 20 || value == 50 || value == 100 || value == 500){
console.log(value + " Real currency");
total+=value;
}
else{
console.log( "Fake currency");
}
}
else{
break;
}
}
console.log(total);

If the user enters a note amount of 10, 20, 50, 100, or 500, then, then it will print '[value Real currency], and the amount will be added to the total

Let's Implement A Currency Corrector Using A While Loop

let currency;
let value;
let total = 0;
while(true){
currency=(prompt("Currency is present enter y:"));
if (currency == "y"){
value=parseInt(prompt("Enter the Note amount:"));
if (value  == 10 ||  value == 20 || value == 50 || value == 100 || value == 500){
console.log(value + " Real currency");
total+=value;
}
else{
console.log( "Fake currency");
}
}
else{
break;
}
}
console.log(total);

If the user enters a note amount of 10, 20, 50, 100, or 500, then, then it will print '[value Real currency], and the amount will be added to the total

OUTPUT:

Let's Implement A Currency Corrector Using A While Loop

let currency;
let value;
let total = 0;
while(true){
currency=(prompt("Currency is present enter y:"));
if (currency == "y"){
value=parseInt(prompt("Enter the Note amount:"));
if (value  == 10 ||  value == 20 || value == 50 || value == 100 || value == 500){
console.log(value + " Real currency");
total+=value;
}
else{
console.log( "Fake currency");
}
}
else{
break;
}
}
console.log(total);

If the user enters a note amount other than 10, 20, 50, 100, or 500, it jumps to the else block and prints 'fake currency'

OUTPUT:

Summary

5

Build strong branding

4

Use different marketing channels

3

Target the right audience

2

Create and communicate value

1

Understand customer needs

Choose cool, soft colors instead of vibrant colors
Max 5 Points for Summary & Min 2

Quiz

Which platform is mainly used for professional networking and B2B marketing ?

A. Facebook

B. Instagram

C. LinkedIn

D. Snapchat

Quiz-Answer

Which platform is mainly used for professional networking and B2B marketing ?

A. Facebook

B. Instagram

C. LinkedIn

D. Snapchat

Copy of OG Template

By Content ITV

Copy of OG Template

  • 5