0% found this document useful (0 votes)
418 views15 pages

JS Essentials CODING TEST 2 Answers

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)
418 views15 pages

JS Essentials CODING TEST 2 Answers

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/ 15

FOLLOW CODING SOLUTIONS YOUTUBE CHANNEL TO GET

ANSWERS FOR ALL ASSIGNMENTS AND CODING TESTS


https://www.youtube.com/channel/UCxQ3ohi9sLWrGhMmxnI
270w

JS Essentials CODING TEST 2 Answers


Note: One Test Case Failed For 1 Question, You
wont get 189/189. You will get 184/189.

1.Car Race

"use strict";

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++];
}

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

// Create your Super Class Race and Sub Class Car here
class Race{
constructor(playerName){
this.playerName=playerName;
// this.nitro=nitro;
// this.speed=speed;
}
startRace(){
return "Race has started";
}
endRace(){
return `${this.playerName} is the winner`;
}
}
class Car extends Race{
constructor(playerName,nitro,speed){
super(playerName);
this.nitro=nitro;
this.speed=speed;
}
applyBreak(){
return this.speed=0;
}
nitroBoost(){
return this.speed+=50, this.nitro-=50;
}
accelerate(){
return this.nitro+=10, this.speed+=20;
}
}

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

function main() {
const playerName = readLine();
const nitro = JSON.parse(readLine());
const speed = JSON.parse(readLine());
const car1 = new Car(playerName, nitro, speed);
console.log(car1.startRace());
car1.nitroBoost();
console.log(`Speed ${car1.speed}; Nitro ${car1.nitro}`);
car1.accelerate();
console.log(`Speed ${car1.speed}; Nitro ${car1.nitro}`);
console.log(car1.endRace());
car1.applyBreak();
console.log(`Speed ${car1.speed}; Nitro ${car1.nitro}`);
}
2.Double the Numbers

"use strict";

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 myArray = JSON.parse(readLine().replace(/'/g, '"'));

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

// Write your code here


let result=myArray.map((el)=>{
if( typeof el==="number"){
return el*2;
}
else{
return typeof el;
}
});
console.log(result);
}

3. Words with Vowels

"use strict";

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 wordsList = JSON.parse(readLine().replace(/'/g, '"'));
const vowelsList = ["a", "e", "i", "o", "u"];

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

// Write your code here


let result=wordsList.filter((word)=>{
for (let char in vowelsList){
if(word.toLowerCase().indexOf(vowelsList[char])>=0){
return word;
}
}
});
console.log(result);
}
4. Flattening and Case Conversion

"use strict";

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 nestedArray = JSON.parse(readLine().replace(/'/g, '"'));
const depth = JSON.parse(readLine());

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

// Write your code here


let flattenedArray=nestedArray.flat(depth)
let result=flattenedArray.map((element)=>{
if(element.length%2!==0){
return element.toUpperCase();
}
else{
return element.toLowerCase();
}
});
console.log(result)
}
5. Selected Words to Uppercase

"use strict";

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 wordsList = JSON.parse(readLine().replace(/'/g, '"'));
const myString = readLine();

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

// Write your code here


let newWordsList=[];
for(let word of wordsList){
if (word.startsWith(myString) || word.endsWith(myString)){
let upperCaseword=word.toUpperCase();
newWordsList.push(upperCaseword);
}
else{
newWordsList.push(word);

}
}
console.log(newWordsList)
}

6. Bunty Birthday
"use strict";

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 birthdaysList = JSON.parse(readLine().replace(/'/g, '"'));
const buntyBirthday = new Date("2000-06-13");

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

// Write your code here


let result={days:0,months:0,years:0};
birthdaysList.map((d)=>{
if (new Date(d).getDate()===buntyBirthday.getDate() && new
Date(d).getMonth()===buntyBirthday.getMonth()){
result.days++;
}
if (new Date(d).getMonth()===buntyBirthday.getMonth()){
result.months++;
}
if (new
Date(d).getFullYear()===buntyBirthday.getFullYear()){
result.years++;
}
});
console.log(result.days);
console.log(result.months);

console.log(result.years);

}
FOLLOW CODING SOLUTIONS YOUTUBE CHANNEL TO GET
ANSWERS FOR ALL ASSIGNMENTS AND CODING TESTS
https://www.youtube.com/channel/UCxQ3ohi9sLWrGhMmxnI
270w

Download Link is Available in the Description.

You might also like