JavaScript for SEBA HSLC class 10

The following question are prepared on the base of HSLC final exam conducted by SEBA board of Assam. These questions comes under Computer Science.Its very necessary for an HSLC candidate to know how to prepare. And also necessary to know what will be  the pattern of the final question papers. That is why we are providing most important questions in an easy and suitable manner so that one can understand it easily, Read it  easily and the most important thing  is one can get it everywhere and any time whenever he or she needs.We are trying our label best to provide more and more but due to lack of fund,we are unable to take necessary actions. So if you are willing to support us financially, please Click here to Donate.Hopefully whole Assam will help us…

Q1.Write a program in JavaScript where user will enter name and displaying the same name with welcome message.

<script type="text/javascript" >
var str=window.prompt(" Enter your name ");
document.write(" Welcome " + str );
</script>

Q2.Check a number is Prime or not using JavaScript.

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        Check a number is Prime or 
        not using JavaScript 
    </title> 
      
    <script type="text/javascript"> 
      
        // Function to check prime number 
        function p() { 
              
            var n, i, flag = true; 
              
            // Getting the value form text 
            // field using DOM 
            n = document.myform.n.value; 
            n = parseInt(n) 
            for(i = 2; i <= n - 1; i++) 
                if (n % i == 0) { 
                    flag = false; 
                    break; 
                } 
                  
                // Check and display alert message 
            if (flag == true) 
                alert(n + " is prime"); 
            else
                alert(n + " is not prime"); 
        } 
    </script> 
</head> 
  
<body> 
    <center> 
        <h1>SEBAHELP</h1> 
          
        <h4>check number is prime or not</h4> 
          
        <hr color="Green"> 
          
        <form name="myform"> 
            Enter the number: 
            <input type="text" name=n value=""> 
              
            <br><br> 
              
            <input type="button" value="Check" onClick="p()"> 
            <br> 
        </form> 
    </center> 
</body> 
  
</html> 

Q3. Write a program in JavaScript to find Odd or Even number.


<!DOCTYPE html>
<html>
<head>
<title>JavaScript to find Odd or Even number</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
function findOddEven(){
//get the input value
var num = document.getElementById('num').value;
//if the value of c is 2 then it is a prime number
//because a prime number should be exactly divisible by 2 times only (itself and 1)
if ( num % 2 == 0) {
document.getElementById('result').innerHTML = num + ' is a Even number';
}else{
document.getElementById('result').innerHTML = num + ' is a Odd number';
}
}
</script>
</head>
<body>
<h2>JavaScript to find Odd or Even number || SEBAHELP</h2>
<form method="post">
Enter a number: <input type="number" id="num" name="num" min="0" /><input type="button" value="Find Odd or Even" onclick="findOddEven()" name="find" />
<div style="margin-top: 10px;" id="result"></div>
</form>
</body>
</html>

Q4.Write a program in javascript to print prime numbers upto user’s limit.

<html>
<head>
<title>JavaScript to print prime numbers!</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>

function printPrime() {
var i = 0;
var j = 0;

limit = document.getElementById('limit').value;

//loop till i equals to $limit
for (i = 1; i <= limit; i++) {
c = 0;

for (j = 1; j <= i; j++) {
// % modules will give the reminder value, so if the reminder is 0 then it is divisible
if (i % j == 0) {
//increment the value of c
c++;
}
}
//if the value of c is 2 then it is a prime number
//because a prime number should be exactly divisible by 2 times only (itself and 1)
if (c == 2) {
document.getElementById("result").insertAdjacentHTML('beforeend', i + '<br>');
}
}
}
</script>
</head>
<body>
<h2>JavaScript to print Prime numbers!</h2>
Enter the limit: <input type="number" name="limit" id="limit" min="0" style="width: 100px;" />&nbsp;<input type="submit" value="Print Prime Numbers" onclick="printPrime()" name="print" />
<div id="result"></div>
</body>
</html>

Q5.Write a program in javascript to reverse a number.

<!doctype html>
<html>
<head>
<script>
function palin()
{
var a,no,b,temp=0;
no=Number(document.getElementById("no_input").value);
b=no;
while(no>0)
{
a=no%10;
no=parseInt(no/10);
temp=temp*10+a;
}
alert(temp);
}
</script>
</head>
<body>
Enter any Number: <input id="no_input">
<button onclick="palin()">Check</button></br></br>
</body>
</html>

Q6. Reverse a string in javascript.

<html>
<head>
<script>

//usage
function doReverse(){
var str = document.getElementById( 'mystring' ).value;
alert( "" + reverseString( str ) );
}

//reverse function
function reverseString( str ){
str = str.split(''); //split the entered string
str = str.reverse(); //reverse the order
str = str.join(''); //then join the reverse order array values
return str;
}

</script>
</head>
<body>
<h3>Reverse a String in JavaScript </h3>
<input type="text" id="mystring" value="" />
<button id="btn" onClick="doReverse()" >Reverse</button>
</body>
</html>

Q7.Calculate largest among three numbers in javascript.

<html>
<head>
<script>
function largest()
{
var num1, num2, num3;
num1 = Number(document.getElementById("N").value);
num2 = Number(document.getElementById("M").value);
num3 = Number(document.getElementById("O").value);

if(num1>num2 && num1>num3)
{
window.alert(num1+"-is greatest");
}
else if(num2>num1 && num2>num3)
{
window.alert(num2+"-is greatst");
}
else if(num3>num1 && num3>num1)
{
window.alert(num3+"is greatest");
}
}
</script>
</head>
<body>
<h1>Calculate largest among three numbers</h1>
<hr color="cyan">
<br>
Enter number 1: <input type="text" id="N"></input><br>
Enter number 2: <input type="text" id="M"></input><br>
Enter number 3: <input type="text" id="O"></input><br>
<hr color="cyan">
<center><button onclick="largest()">CLICK HERE TO FIND LARGEST NUMBER</button>
</body>
</html>

Q8. Check a number is palindrome or not in javascript.

<!doctype html>
<html>
<head>
<script>
function palin()
{
var a,no,b,temp=0;
no=Number(document.getElementById("no_input").value);
b=no;
while(no>0)
{
a=no%10;
no=parseInt(no/10);
temp=temp*10+a;
}
if(temp==b)
{
alert("Palindrome number");
}
else
{
alert("Not Palindrome number");
}
}
</script>
</head>
<body>
Enter any Number: <input id="no_input">
<button onclick="palin()">Check</button></br></br>
</body>
</html>

Q9.Generate fibonacci series in javascript.

<!DOCTYPE HTML>
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<title> fibonacci.html </title>
</head>
<body>
<h3 style="text-align:center; color:white"> Program to generate the Fibonacci Series </h3>
<script type="text/javascript">

var limit = prompt("Enter the limit 'n' to generate the fibonacci series:", " ");
var f1=0;
var f2=1;

document.write("The limit entered to generate the fibonacci series is: ",limit, "<br/>");
document.write("The fibonacci series : ");
document.write("",f1," ");
document.write("",f2," ");

var i,f3;
for(i=2; i<limit; i++)
{
f3=f1+f2;
document.write("",f3," ");
f1=f2;
f2=f3;
}

</script>
</body>
</html>

Q10.If a given year is leap year or not.

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        JavaScript to check leap year 
    </title> 
</head> 
  
<body> 
    Input Year: <input type="text" id = "year"/> 
      
    <input type="button" id="button" onClick="isLeapYear()"
            value="Check Leap Year"> 
      
    <p id="GFG"></p> 
      
    <!-- JavaScript code to check given year is 
        leap year or not -->
    <script> 
        function isLeapYear() { 
            var year= document.getElementById("year").value; 
              
            document.getElementById("GFG").innerHTML  
                = (year % 100 === 0) ? (year % 400 === 0) 
                                     : (year % 4 === 0); 
        } 
    </script> 
</body> 
  
</html>

Q 11.Print Triangle of Stars in JavaScript.


<html>
<head>
<script type="text/javascript">
var i, j;
//outer loop
for(i=1; i <= 5; i++)
{
//inner loop
for(j=1; j<=i; j++)
{
document.write('*');
}
document.write('<br/>');
}
</script>
</head>
<body>
</body>
</html>

Q 12.Print the following pattern in javascript.

*****

****

***

**

*


<html>
<head>
<script type="text/javascript">
var i, j;
//outer loop
for(i=5;i>=1;i--)
{
//inner loop
for(j=1;j<=i;j++)
{
document.write('*');
}
document.write('<br/>');
}
</script>
</head>
<body>
</body>
</html>

Q 13.Find sum of two numbers using javascript.

<!doctype html>
<html>
<head>
<script>
function add(){
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c= a + b;
document.getElementById("answer").value= c;
}
</script>
</head>
<body>
Enter the First number : <input id="first">
Enter the Second number: <input id="second">
<button onclick="add()">Add</button>
<input id="answer">
</body>
</html>

Q 14.Swap two number in javascript.

<!doctype html>
<html>
<head>
<script>
function swap(){
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c=a;
a=b;
b=c;
document.getElementById("answer1").value= a;
document.getElementById("answer2").value= b;
}
</script>
</head>
<body>
Value of a: <input id="first">
Value of b: <input id="second"></br></br>
<button onclick="swap()">Swap</button></br></br>
Value of a: <input id="answer1">
Value of b: <input id="answer2">
</body>
</html>

Q 15. JavaScript to convert Fahrenheit to Celsius.

<html>
<head>
<script>
//find celsius from fahrenheit javascript function
function findCelsius(){
var fahrenheit = document.getElementById("fahrenheit").value;
var celsius;
if(fahrenheit != ''){
celsius = (fahrenheit - 32) * 5/9;
document.getElementById("output").innerHTML = celsius;
}else{
document.getElementById("output").innerHTML = "Please enter a value!";
}
}
</script>
</head>
<body>
<h2>Enter Fahrenheit</h2>
<input type="text" id="fahrenheit" />
<button onclick="findCelsius()" >Find Celsius</button>
<h4>Output: <span id="output"></span></h4>
</body>
</html>

LEAVE A REPLY

Please enter your comment!
Please enter your name here