0% found this document useful (0 votes)
166 views12 pages

ccbp js essentials

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views12 pages

ccbp js essentials

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

JS Essentials CODING TEST 1 Answers

Coding Solutions Youtube Channel

Note: Few Test Cases Failed For 2 Questions,


You wont get 146/146. You will get 134/146.
1.Month & Season

"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";


let currentLine = 0;

process.stdin.on("data", (inputStdin) => {


inputString += inputStdin;
});
Coding Solutions Youtube Channel
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});

function readLine() {
return inputString[currentLine++];
}

function main() {
const month = readLine();
/* Please do not modify anything above this line */

// Write your code here


switch (month) {
case 'December':
console.log("Winter");
break;
case 'January':
console.log("Winter");
break;
case 'February':
console.log("Spring");
Coding Solutions Youtube Channel
break;
case 'March':
console.log("Spring");
break;
case 'April':
console.log("Summer");
break;
case 'May':
console.log("Summer");
break;
case 'June':
console.log("Summer");
break;
case 'July':
console.log("Monsoon");
break;
case 'August':
console.log("Monsoon");
break;
case 'September':
console.log("Monsoon");
break;
case 'October':
console.log("Autumn");
break;
Coding Solutions Youtube Channel
case 'November':
console.log("Autumn");
break;
default:
console.log("Invalid Month");
}
}
2.Employee & Tax

"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";


let currentLine = 0;

process.stdin.on("data", (inputStdin) => {


inputString += inputStdin;
Coding Solutions Youtube Channel
});

process.stdin.on("end", (_) => {


inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});

function readLine() {
return inputString[currentLine++];
}

function main() {
const name = readLine();
const role = readLine();
const salary = JSON.parse(readLine());
let taxPercent=0;
function Employee(name, role, salary) {
/* Please do not modify anything above this line */
this.name=name;
this.role=role;
this.salary=salary;
this.getTaxAmount=function (){
if (this.salary>=500000){
taxPercent=5;
}
else if(this.salary>=1000000){
Coding Solutions Youtube Channel
taxPercent=10;
}
return this.salary*taxPercent/100;
};
// Write your code here

const employee1 = new Employee(name, role, salary);

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


console.log(employee1.getTaxAmount());
}

3.Daily Routines

"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";


Coding Solutions Youtube Channel
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {


inputString += inputStdin;
});

process.stdin.on("end", (_) => {


inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});

function readLine() {
return inputString[currentLine++];
}

function main() {
const isHotWaterReady = JSON.parse(readLine());
const isBreakfastReady = JSON.parse(readLine());

const takingShower=()=>{
return new Promise((resolve,reject)=>{
isHotWaterReady ? resolve("Taken Shower"):reject("Hot
Water Not Ready")
});
};
Coding Solutions Youtube Channel
const breakFast=()=>{
return new Promise((resolve,reject)=>{
isHotWaterReady ? resolve("Had
Breakfast"):reject("Breakfast Not Ready");
});
};

takingShower()
.then(result=>{
console.log(result);
return breakFast();
})
.then(result=>{
console.log(result);
return "Got to Work";
})
.then(result=>console.log(result))
.catch(error=>console.log(error))
}

4. Candidate Selections

Coding
"use strict"; Solutions Youtube Channel

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";


let currentLine = 0;

process.stdin.on("data", (inputStdin) => {


inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});

function readLine() {
return inputString[currentLine++];
}

function main() {
const candidatesList = JSON.parse(readLine().replace(/'/g, '"'));

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


Coding Solutions Youtube Channel
// Write your code here
let result=candidatesList.filter((candidate)=>{
if (candidate.points.every((point)=>point>75))
return candidate;
});
let candidate=result.map((candidate)=>candidate.name)
console.log(candidate)
}
5.Get the Chunk

"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";


let currentLine = 0;

process.stdin.on("data", (inputStdin) => {


inputString += inputStdin;
});
Coding Solutions Youtube Channel
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});

function readLine() {
return inputString[currentLine++];
}

function main() {
const myString = readLine();
const startString = readLine();
const endString = readLine();

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


let startIndex=myString.indexOf(startString);
let endIndex=myString.indexOf(endString)
let slicedString=myString.slice(startIndex,endIndex)
console.log(slicedString)
}

Coding Solutions Youtube Channel

You might also like