hackersguild / AssignmentQuestions

The questions for assignments

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Objects and Arrays

Questions will include : Loops and conditions The questions for assignments

DOM

  1. Here is a sample html file with a submit button. Now modify the style of the paragraph text through javascript code. Sample HTML file :
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS DOM paragraph style</title>
</head> 
<body>
<p id ='text'>JavaScript Exercises - w3resource</p> 
<div>
<button id="jsstyle"
onclick="js_style()">Style</button>
</div>
</body>
</html> 
  1. Write a JavaScript function to get the values of First and Last name of the following form. Sample HTML file :
<!DOCTYPE html> 
<html><head> 
<meta charset=utf-8 /> 
<title>Return first and last name from a form - w3resource</title> 
</head><body> 
<form id="form1" onsubmit="getFormvalue()"> 
First name: <input type="text" name="fname" value="David"><br> 
Last name: <input type="text" name="lname" value="Beckham"><br> 
<input type="submit" value="Submit"> 
</form> 
</body> 
</html>
  1. Write a JavaScript program to set the background color of a paragraph.

  2. Here is a sample html file with a submit button. Write a JavaScript function to get the value of the href, hreflang, rel, target, and type attributes of the specified link.

<!DOCTYPE html> 
<html><head> 
<meta charset=utf-8 /> 
</head> 
<body> 
<p><a id="w3r" type="text/html" hreflang="en-us" rel="nofollow" target="_self" href="https://www.w3resource.com /">w3resource</a></p> 
<button onclick="getAttributes()">Click here to get  attributes value</button> 
</body></html>

Arrays

1 . Write a JavaScript function to get the first element of an array. Passing a parameter 'n' will return the first 'n' elements of the array.

2 . Write a JavaScript function to get the last element of an array. Passing a parameter 'n' will return the last 'n' elements of the array.

3 . Write a simple JavaScript program to join all elements of the following array into a string.
Sample array : myColor = ["Red", "Green", "White", "Black"]; Expected Output : "Red,Green,White,Black" "Red,Green,White,Black" "Red+Green+White+Black"

4 . Write a JavaScript program which accept a number as input and insert dashes (-) between each two even numbers. For example if you accept 025468 the output should be 0-254-6-8.

5 . Write a JavaScript program to sort the items of an array. Sample array : var arr1 = [ 3, 8, 7, 6, 5, -4, 3, 2, 1 ]; Sample Output : -4,-3,1,2,3,5,6,7,8

Conditional statements and loops

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

  2. Write a JavaScript conditional statement to find the sign of product of three numbers. Sample numbers : 3, -7, 2 Output : The sign is -

  3. Write a JavaScript conditional statement to sort three numbers. Sample numbers : 0, -1, 4 Output : 4, 0, -1

  4. Write a JavaScript conditional statement to find the largest of five numbers. Sample numbers : -5, -2, -6, 0, -1 Output : 0

  5. 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. Sample Output : "0 is even" "1 is odd" "2 is even"

6 . Write a JavaScript program which iterates the integers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

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

*  
* *  
* * *  
* * * *  
* * * * *
  1. Write a JavaScript program to sum the multiples of 3 and 5 under 1000.

About

The questions for assignments