Assignment Questions

Assignment Questions

Assignment Questions

Qs 1.

Create a number variable num with some value now , print good if the number is divisible by 10 and print “bad if it is not

code

//let num = 9;
let num = 20;

if( num % 10 == 0){
    console.log("good");
}else{
    console.log("bad")
}

console

let num = 20;

GOOD


let num = 9;

Bad

Qs 2.

Take the user’s name & age as input using prompts. Then return back the following statement to the user as a alert ( by substituting their name % age )

code

let name = prompt("Enter your Name");
let age = prompt("Enter you age");
alert(`${name} is ${age} your old.`);

output

Qs 3.

Write a switch statement to print the months in a quarter

Months in Quarter 1 : January , February , March Months in Quarter 2 : April , May , June

Months in Quarter 3 : July , August , September

Months in Quarter 4 : October , November , December

code

let quarter = 1;

switch (quarter) {
    case (1):
        console.log("january , february , march");
        break;
    case (2):
        console.log("April , may , june ");
        break;
    case (3):
        console.log("july , August , September");
        break;
    case (4):
        console.log("October , November , December");
        break;
    default:
        console.log("some thing is worng");

}

output

Qs 4.

A string is a Golden string if it starts with the character ‘A’ OR ‘a’ and has a total length greater than 5 .

for give a given string print if it is golden or not.

code

let str = "apples";

if( (str[0] == 'a' || str[0] == "A") && (str.length > 5)){
    console.log("string is Golden");
}else{
    console.log("string is not Golden");
}

output

Qs 5.

Write a program to find the of 3 numbers;

code

let a = 69;
let b = 54;
let c = 23; 

if(a > b){
    if(a > c){
        console.log(a," is largest");
    }else{
        console.log(c, "is largest");
    }
} else {
        if(b > c){
            console.log(b,"is largest");
        }else{
            console.log(c, "is larfest");
        }
    }

output

Qs 6.

write a program to check is 2 number have the same last digit

Eg.

: 32

: 47852

have the same last digit i.e 2

solution

Logic to be Implemented

  • suppose we have three number num1 , num2

  • To check if all of them have the same last digit.

             Divide each number by 10
    

matlab agar humne do number liye. 32 , 47852 Isko humne 10 se divide karenge aur jo reminder bachta hai vah same aaya To vah number ke last Mein same number hoga

: 32

: 47852

  • check the remainder.

  • If all the remainder are same , those number has the same last digit.

program

Qs 1

code

let numa = 32;
let numb = 47852;

if (( numa % 10 ) == (numb % 10)){
    console.log("number have the same last digit which is",numa%10);
}else{
    console.log("number don't have the same number " );
}

output

Qs 2

code

let num1 = prompt("enter 1 the number");
let num2 = prompt("Enter 2 the number");
let num3 = prompt("enter 3 the numer");

a = num1%10;
b = num2%10;
c = num3%10;

if(`${a}, ${b}, ${c}`){
    console.log(a, b, c,"The last number is same");
}else{
    console.log("The last number is not same");
}

output