Monday, July 4, 2022

How to print JavaScript table in reverse order program Programmatically

 If you want to print table in JavaScript here what you can do . In this example we going to print table of 8 programmatically . below is explanation and at end of explanation you will get code 

Step no 1 

lets declare variable j =8 ;

since we want to print  table of 8 

Step no 2

user while loop or for loop

since it is in reverse order our starting point is 10 , we will run loop until i reach to 1 and i-- mean i =i-1 so we will not going to increment instead we will decrement by one . so in our case loop start with 10 and check if i is greater than one , it will loop until i reach to 1.

Document .write is used for print or observe in browser if you want to use console you can simple replace console.log

now we use variable j which we store value (in this case 8) and we we use i it means it will print position of i and at last we are using j*i it means value of j is 8 and times position of i until value of i reaches to i . 

if you want to print table of 10 in reverse order simple change value of j to 10. Below is code and out put.  


     j = 8
    for(let i=10;i>=1;i--){
        document.write(`${j} times ${i} is ${j*i}<br>`)  
        console.log(`${j} times ${i} is ${j*i}`)      


 -                                                                      out put:

java switch statement | Java Tutorial For Beginners

 Switch statement is alternative and more cleaner way to write code if we have more than two options. we can use else if, this is better way...