Skip to content

DataOps Blog

Just another DataOps site

  • Home
  • certification
  • consultant
  • consulting
  • Contact Us!
  • courses
  • Intro to Laravel
  • tools
  • trainer
  • training

Top 5 Basic Programming Question for interview purpose in JS.

February 8, 2022
By Subham Kumar Mishra In Uncategorized

Top 5 Basic Programming Question for interview purpose in JS.

Q1. Write a program in JavaScript that accept two integers and display the larger.

Ans.

code :-

var num1,num2;

num1= window.prompt("enter the value of num1");
num2= window.prompt("enter the value of num2");

if(num1>num2)
{
     console.log("num1 is greater");
}
else if( num2>num1)
{
    console.log("num2 is greater");
}
else
{
    console.log("both are equal");
}

Q2. Write a JavaScript for loop that will iterate from 0 to 15. For each iteration, it will check if the current number is odd or even, and display a message to the screen.

Ans.
code :-


for(var x=0; x<=15; x++)
{
    if(x===0)
    {
        console.log(x +"is even ");
    }
    else if(x%2===0)
    {
        console.log(x +"is even");

    }
    else{
        console.log(x +"is odd");
    }
}

Q3. Write a JavaScript program to construct the following pattern, using a nested for loop.

*  
* *  
* * *  
* * * *  
* * * * *  

Ans.  
     code :-
var x,y,r;
for(x=1; x <=6; x++)
{
   for (y=1; y < x; y++)
     {
       r=r+("*");        
      }
 console.log(r);
  r='';    
}

Q4.  Write a JavaScript program to compute the greatest common divisor (GCD) of two positive integers.

Ans.

Code :-

var a=7666;
var b=54;
var gcd;
while(a!=b)
{
    if(a>b)
    {
        a=a-b;
    }
    else
    {
       b=b-a;
    }
}
gcd =a;
console.log(gcd);

Q5. Write a JavaScript conditional statement to sort three numbers. Display an alert box to show the result. 

Ans.

Code :-

var x=0, y=-1 , z=4;
if(x>y && x>z)
{
    if(y>z)
    {
        
        console.log(x+","+y+","+z );
    }
    else
    {
        console.log(x+","+z+","+y );
    }
}

else if(y>x && y>z)
{
    if(x>z)
    {
        
        console.log(y+","+x+","+z );
    }
    else
    {
        console.log(y+","+z+","+x );
    }
}

else if(z>x && z>y)
{
    if(y>x)
    {
        
        console.log(z+","+y+","+x );
    }
    else
    {
        console.log(z+","+x+","+y );
    }

Tanku

Written by:

Subham Kumar Mishra

View All Posts

Recent Posts

  • Kubernetes CKA Training Course & Official Master Certification Program
  • Elastic Training Course & Official Master Certification Program
  • Prometheus Training Course & Official Master Certification Program
  • AppDynamics Training Course & Official Master Certification Program
  • Dynatrace Training Course & Official Master Certification Program
  • Grafana Training Course & Official Master Certification Program
  • Newrelic Training Course & Official Master Certification Program
  • Splunk Training Course & Official Master Certification Program
  • Datadog Training Course & Official Master Certification Program
  • Zabbix Training Course & Official Master Certification Program
  • MLOps Training Course & Official Master Certification Program
  • DataOps Training Course & Official Master Certification Program
  • AiOps Training Course & Official Master Certification Program
  • Gitops Training Course & Official Master Certification Program
  • SRE Training Course & Official Master Certification Program
  • DevSecOps Training Course & Official Master Certification Program
  • DevOps Training Course & Official Master Certification Program
  • Best Blog website for Health and Fitness mymedicplus.com/blog
  • Top 5 Basic Programming Question for interview purpose in JS.
  • JAVA SCRIPT VARIABLE AND DATATYPE.

Archives

Categories

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
  • Free Video Tutorials
  • DevOps School
  • Best DevOps
  • scmGalaxy
  • Artificial Intelligence
  • DataOps
  • AIOps
  • GuruKul Galaxy
  • DevOps Consulting
  • DevOps Freelancers
  • DevOps Trainer
  • Free Ebooks
  • School for Debugger
  • Holiday Landmark
  • Surgery Planet
  • My Hospital Now
  • My Medic Plus
  • ProfessNow
  • Cotocus
  • Stocks Mantra
  • I Reviewed

Proudly powered by WordPress | Theme: BusiCare by SpiceThemes