JavaScript Practice Assignments, Quizzes of Programming Languages

A list of JavaScript practice exercises covering topics such as operators, implicit coercion, datatypes, arrays, loops, scope, form validation, DOM & BOM, and ES6. The exercises include tasks such as practicing expressions with operators, finding duplicates in an array, checking if a string contains certain words, and using array helper functions. code snippets for each task and encourages the reader to try them out in the browser to check their progress.

Typology: Quizzes

2022/2023

Available from 09/12/2022

technicalurvashi
technicalurvashi 🇮🇳

4 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Technical Urvashi
P
A
G
E
5
Operators:
1. Practice expression with operators
2. Study Operator precedence (https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
var x = ++num //take num = 20
var y = num++ //take num = 10
3. Try this in browser: (true == false) > 2
4. Practice Post & Pre Increment(++) & decrement(--). Try all below questions on your
own, then execute in browser to check your progress.
var val = 23;
var t = ++val;
val++;
console.log(val)
console.log(t);
var numVal = 30;
var u = --numVal;
numVal++;
console.log(u);
console.log(numVal);
var a = 40;
var b = a++;
b++;
console.log(a);
console.log(b);
var f = 50;
var g = f++;
g--;
console.log(g);
console.log(f);
var val = 10;
val++;
var h = --val;
h++;
console.log(h);
console.log(val);
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download JavaScript Practice Assignments and more Quizzes Programming Languages in PDF only on Docsity!

A

G

E

Operators:

  1. Practice expression with operators
  2. Study Operator precedence (https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) var x = ++num //take num = 20 var y = num++ //take num = 10
  3. Try this in browser: (true == false) > 2
  4. Practice Post & Pre Increment(++) & decrement(--). Try all below questions on your own, then execute in browser to check your progress. var val = 23; var t = ++val; val++; console.log(val) console.log(t); var numVal = 30; var u = --numVal; numVal++; console.log(u); console.log(numVal); var a = 40; var b = a++; b++; console.log(a); console.log(b); var f = 50; var g = f++; g--; console.log(g); console.log(f); var val = 10; val++; var h = --val; h++; console.log(h); console.log(val);

A

G

E

var num = 20; num++; var t = ++num; num++; --num console.log(num, t); var num = 10; --num; var y = ++num + 10; --y; console.log(y); console.log(num); var num = 30; ++num; num++ - 10; console.log(num);

Implicit coercion: Practice questions on implicit coercion

  1. Try these first, then execute in browser to check progress. console.log('A' - 1);// console.log('A' + 1);// console.log(2 + '2' + '2');// console.log('hello' + 'world' + 89);// console.log('hello' - 'world' + 89);// console.log('hello' + 78);// console.log('78' - 90 + '2');// console.log(2 - '2' + 90);// console.log(89 - '90' / 2);//

Datatypes:

  1. Extract first five letters from a string ('gfuh ieiuei')
  2. Get the length of a string and make it uppercase ('hduej dij')
  3. Take a string, make it uppercase and trim it (' biji jdo ')
  4. Revise type of each datatype
  5. Replace specified word in a string ('', '')
  6. Random statements in implicit coersion e.g. (89 + 'hello' + 90 / 9)
  7. Try this: (2 + '2' + null);
  8. Find the duplicate in a string() (use array)
  9. Reverse a string (use array method)
  10. Find the highest and lowest value in array
  11. Sorting of an array (employee data structure)

A

G

E

  1. Create a ATM Machine with below features.  balance & query  withdraw (amount)  change pin  mini statement  saving & current acc.  print receipt  enter pin number
  2. Given alphabet is vowel or consonant
  3. Calculate Simple interest ((p/r * t) * 100 )
  4. Given year leap year or not
  5. 0 - 6 display day week depending upon what user is entering (0-> sunday)

Loops: Use loops, conditional statements, take input from user for below task.

  1. multiplication table (ask number from user)
  2. sum of digits (123: 1 + 2 + 3 = 6) or (1234 : 1 + 2 + 3 + 4 = 10)
  3. palindrome string (aca: aca is a palindrome, abc: cba is not a palindrome)
  4. display even numbers up to n number (ask user for number)
  5. keep asking user for the input, whether char is vowel or consonant
  6. count of even and odd number from 1 to 999
  7. count occurrence of a particular character in a string (hello: count of l is 2)
  8. sum and average of array elements [1, 9, 8];
  9. largest number in an array (do with loops)
  10. From 1 to 100, print "foo" if multiple of 3, "bar" if multiple of 5, if multiple of both display "hello" or else print the number e.g. 1 2 foo 4 bar foo

Type conversion

  1. (+infinity , - infinity) in js
  2. Practice type conversion Boolean, string, numbers
  3. Add only even numbers in an array (array elements to be input by user)
  4. Found an element in array [10, 78, 90] return 90 otherwise exit from an array.

Regex

 Find first letter in a string is uppercase or lowercase through regex (e.g. 'hello world')  Take input from user as name and display it( urvashi :urvashi)  Find count of vowels in a string (aeiou)

A

G

E

 Find a digit in a string (e.g: hello789: 789)  Find all the consonants in string  Check whether a given value is alphanumeric or not (e.g: hello789: yes)  email regex, try test method on this  check given value(string) contains alpha, underscore, dash  check given url is valid or not (e.g. http://www.amazon.in)

More Practice task on arrays & loops

  1. Ask array elements from user  Smallest number in an array  Biggest of even number in an array ([10, 12, 90, 93, 7]): biggest even number is 90  Add two array [10,20,30] + [1,2,3]: [11, 22, 33]  Reverse an array(with loops) [10, 78, 0]: [0, 78, 10]  Remove duplicate items from an array [10, 50,20 67, 10, 20]: remove 10, 20  Find duplicate values in an array.(display index of duplicate values e.g. 0,2,4,5)  Find difference/subtraction in 2 arrays //[12, 56, 789] - [12, 56, 789]: [0, 0, 0]  Ask user, remove a specific element from an array [12, 56, 89]: remove 1 element  on click of a button, add random element to an array [12]  array, check given elements palindrome or not [124, 121, 900, 565]  array, for each element multiply by 2 [1, 2, 4]: [2, 4, 8]  multiply 2 array [1, 2, 3 ] * [1, 1, 1 ]: [1, 2, 3]

Scope:

  1. Try scope create a method add, subtract ,multiply

Form

 Create a form and validate it: email, contact, name, age, designation, select multiple files

DOM & BOM

 Timing events (setTimeInterval(), setTimeout())  Fetch the index.html part of the current url  Revise DOM & BOM

Timing Events:

  1. Create a clock show locale time (localestring) and display it in UI

A

G

E

 Round off all the decimal numbers in an array and sum all the values [9.8, 9.7, 4.5, 3.4]  Get all the person name based on age greater than and equal to 18, eligible to vote [{ firstName: 'joe', age: 24 }, { firstName: 'alina', age: 12 }, { firstName: 'alex', age: 20 } ]  Sum all the elements of an array [90, 89, 56, 45]  Check element is odd or even in an array [90, 89, 56, 45]  Sum of all the salaries and display final sum value [{ salary: 56000, id: 1 }, { salary: 90000, id: 2 }]  Concatenation of all array elemets ['pink', 'blue', 'green', 'red']: 'pinkbluegreenred'

Class

  1. Create a class Car: city(), specialFeature() name, brand, color, manufactureYear
  2. Create a class Book: type_of_book() no. of pages, type of pages, author
  3. Create a class Animal: walk(), eat(), climb() gender, name, disease

A

G

E

Inheritance :

  1. Create parent class: Electronics (methods: name, version, company name) and child class(laptop, ipad, mobile, tablet): create methods” configuration, price()

Advance Task (based on es6)

1.Symmetric difference of 2 arrays const arrOne = [{ id: 20, name: 'alex' }, { id: 30, name: 'alina' }] const arrTwo = [{ id: 40, name: 'hello' }, { id: 30, name: 'world' } ] result = [{ id: 20, name: 'alex' }, { id: 40, name: 'hello' }] Result = [{ id: 40, name: 'hello' },{ id: 40,