HTML/JavaScript Web Application Answers

Questions: 680

Answers by our Experts: 648

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

String Starts or Ends with given String


Given an array

stringsArray of strings, and startString, endString as inputs, write a JS program to filter the strings in stringsArray starting with startString or ending with endString.


Quick Tip

You can use the array method filter() and logical operator OR ( || ).



function main() {

 const stringsArray = JSON.parse(readLine().replace(/'/g, '"'));

 const startString = readLine();

 const endString = readLine();


 /* Write your code here */

}


Gardening

We have a task to do Gardening.

Given two boolean values

isGrassTrimmerFound and isWaterHosePipeFound as inputs, create three JS promises using async/await and try/catch blocks. 


/* Please do not modify anything above this line */


function main() {

 const isGrassTrimmerFound = JSON.parse(readLine());

 const isWaterHosePipeFound = JSON.parse(readLine());


 /* Write your code here */


 const myPromise = async () => {

  try {

   

   /* Write your code here */

    

  } catch(error) {


   /* Write your code here */

    

  }

 };

  

 myPromise();

}



String Slicing


Given two strings

inputString and subString as inputs, write a JS program to slice the inputString if it includes the subString. Slice the inputString starting from the subString to the end of the inputString.
Input

  • The first line of input contains a string inputString
  • The second line of input contains a string subString

Output

  • The output should be a sliced string or inputString (if the inputString does not include the subString)


Sample Input 1

JavaScript

S


Sample Output 1

Script


Sample Input 2

Language

air


Sample Output 2

Language




Trekking Kit


function Trekking(kit, item) {

 this.kit = kit;

 this.item = item;

}


function main() {

 const item = readLine();

 const trekkingKit = {

  ruckSackBag : true,

  clothes: ["Shirt", "T-Shirt/Full sleeves","Jeans"],

  firstAid: true,

  waterBottle: "2 liters",

  sunGlasses: "UV Protection",

  headTorch: true,

  medicines: true,

  footWear: "Non-skid",

  food: ["dry fruits", "nuts", "chocolate bars"]

 };

  

 /* Write your code here */

}


Sample Input 1

ruckSackBag

Sample Output 1

true

Sample Input 2

surfboard

Sample Output 2

false


i want code in between write code here


Unite Family

Given three objects

father, mother, and child, write a JS program to concatenate all the objects into the family object using the spread operator.Input

  • The first line of input contains an object father
  • The second line of input contains an object mother
  • The third line of input contains an object child

Output

  • The output should be a single line string with the appropriate statement as shown in sample outputs

Constraints

  • Keys of the objects should be given in quotes


SampleInput 1

{'surname' : 'Williams', 'city': 'Columbia'}

{'dish': 'cakes'}

{'pet': 'Rocky'}


Sample Output 1

Mr and Mrs Williams went to a picnic in Columbia with a boy and a pet Rocky. Mrs Williams made a special dish "cakes"


Sample Input 2

{'surname' : 'Jones', 'city': 'Los Angeles'}

{'dish': 'puddings'}

{'pet': 'Peter'}

Sample Output 2

Mr and Mrs Jones went to a picnic in Los Angeles with a boy and a pet Peter. Mrs Jones made a special dish "puddings"






Array of Strings to UpperCase

Given an array

myArray of strings as an input, write a JS program to convert all the strings in myArray to uppercase.
Input

  • The input will be a single line containing an array myArray

Output

  • The output should be a single line containing an array of strings in uppercase


Sample Input 1

[ 'book', 'table', 'strawberries', 'lemons' ]


Sample Output 1

[ 'BOOK', 'TABLE', 'STRAWBERRIES', 'LEMONS' ]


Sample Input 2

[ 'my best friend', 'florida', 'winter' ]


Sample Output 2

[ 'MY BEST FRIEND', 'FLORIDA', 'WINTER' ]




Trekking Kit


Given an object


trekkingKit in the prefilled code and item item as an input, write a JS program to add the method isKitContains to the constructor function Trekking using the prototype.


The method


isKitContains checks whether the trekkingKit contains the given item.


Quick Tip

The Object.getOwnPropertyNames() method gives an array containing the properties of the object.

Input


The input will be a single line containing a string


item


Output


The output should be a single line containing a boolean value


Sample Input 1

ruckSackBag

Sample Output 1

true


Sample Input 2

surfboard

Sample Output 2

false


Hotel Bill

A Hotel is offering discounts to its customers.

Given charge per day

dayCharge based on category and numbers of days customer stayed days as inputs, write a JS arrow function to return the total bill with the discount.


Quick Tip

  • The formula for bill is,
  • bill = dayCharge * days
  • The formula to calculate the discounted bill,
  • bill - (bill * discount) / 100

Apply discounts on the following basis,

  • 5%, if the customer stays more than 2 days
  • 15%, if the customer stays more than 5 days

Input

  • The first line of input contains a number dayCharge
  • The second line of input contains a number days

Output

  • The output should be a single line containing the total bill with the discount


Sample Input 1

200

3


Sample Output 1

570


Sample Input 2

180

1


Sample Output 2

180

Sample Input 2

400

6


Sample Output 2

2040


Search Item in a Mart


Given an array mart of objects in the prefilled code and categoryOfItem, item as inputs, create a JS promise, resolve with "Item Found" text, if the categoryOfItem matches with the category and the corresponding items list includes the item reject with "Category Not Found" text, if the categoryOfItem does not match with any catergory in the mart reject with "Item Not Found" text, if the items list does not include item Use async/await and try/catch blocks.


Quick Tip

You can use array methods find() and includes().


Input

The first line of input contains a string categoryOfItem The second line of input contains a number item


Output

The output should be a single line string with the appropriate message


Sample Input 1

pulses

green gram

Sample Output 1

Item Found


Sample Input 2

detergents

tide


Sample Output 2

Category Not Found

Unite Family


Given three objects

father, mother, and child, write a JS program to concatenate all the objects into the family object using the spread operator.Input

  • The first line of input contains an object father
  • The second line of input contains an object mother
  • The third line of input contains an object child

Output

  • The output should be a single line string with the appropriate statement as shown in sample outputs

Constraints

  • Keys of the objects should be given in quotes


Sample Input

{'surname' : 'Jones', 'city': 'Los Angeles'}

{'dish': 'puddings'}

{'pet': 'Peter'}


Sample Output

Mr and Mrs Jones went to a picnic in Los Angeles with a boy and a pet Peter. Mrs Jones made a special dish "puddings"




LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS