- Notifications
You must be signed in to change notification settings - Fork305
JavaScript Test 3
Asabeneh edited this pageMay 4, 2019 ·13 revisions
Try to solve the question by yourself before you check thesolutions
- Write a function which count the number of occurrence of a word in a paragraph or a sentence.The function countWords takes a paragraph and word as parameters.
constparagraph='I love teaching. If you do not love teaching what else can you love. I love JavaScript if you do not love something which can give life to your application what else can you love.';console.log(countWords(paragraph,'love'));6
- Write a function which takes an array parameter and returns an array of the data types of each item:
constarr=['Asabeneh',100,true,null,undefined,{job:'teaching'}];console.log(checkDatatTypes(arr));["string","number","boolean","object","undefined","object"]constmixedData=["John",25,"David",30,"Sara",22];console.log(checkDatatTypes(mixedData));["string","number","string","number","string","number"];
- Create a function which filter ages greater than 18.
constages=[35,30,17,18,15,22,16,20];console.log(agesGreaterEighteen(ages));[35,30,22,,20];
- Write a function which calculate the average age of the group.
console.log(averageAge(ages));22
Write a function which remove an item or items from the middle of the array and replace with two items
Write a function which can generate a random Finnish car code.
console.log(genCarPlateNum())AFG-205console.log(genCarPlateNum())JCB-586
- Write a function which can generate a random Finnish social security number.
console.log(genSocialSecurityNum())220590-255Hconsole.log(genSocialSecurityNum())190395-225J
- The following shopping cart has four products. Create an addProduct, removeProduct ,editProduct , removeAll functions to modify the shopping cart.
constshoppingCart=['Milk','Coffee','Tea','Honey'];addProduct("Meat");["Milk","Coffee","Tea","Honey","Meat"]editProduct(3,"Sugar");["Milk","Coffee","Tea","Sugar","Meat"]removeProduct(0);["Coffee","Tea","Sugar","Meat"]removeProduct(3);["Coffee","Tea","Sugar"]
- The following todoList has three tasks. Create an addTask, removeTask, editTask, toggleTask, toggleAll, removeAll functions to modify the todoList.
consttodoList=[{task:'Prepare JS Test',time:'4/3/2019 8:30',completed:true},{task:'Give JS Test',time:'4/3/2019 10:00',completed:false},{task:'Assess Test Result',time:'4/3/2019 1:00',completed:false}]
- Write a function which check if items of an array are unique?
constarrOne=[1,4,6,2,1];console.log(checkUniqueness(arrOne));falseconstarrTwo=[1,4,6,2,3]console.log(checkUniqueness(arrTwo));true
- Write a function named shuffle, it takes an array parameter and it returns a shuffled array.
console.log(shuffle([1,2,3,4,5]);[3,1,5,2,4]
Write a function which filter users who has scoresGreaterThan85,Write a function which addUser to the user array only if the user does not exist.Write a function which addUserSkill which can add skill to a user only if the user exist.Write a function which editUser if the user exist in the users array.
constusers=[{name:'Brook',scores:75,skills:['HTM','CSS','JS'],age:16},{name:'Alex',scores:80,skills:['HTM','CSS','JS'],age:18},{name:'David',scores:75,skills:['HTM','CSS'],age:22},{name:'John',scores:85,skills:['HTM'],age:25},{name:'Sara',scores:95,skills:['HTM','CSS','JS'],age:26},{name:'Martha',scores:80,skills:['HTM','CSS','JS'],age:18},{name:'Thomas',scores:90,skills:['HTM','CSS','JS'],age:20}];