10 Days of Javascript
in Algorithm on HackerRank
Day 0: Hello, World! Problem : Hello, World
My code :
function greeting(parameterVariable) {
// This line prints 'Hello, World!' to the console:
console.log('Hello, World!');
// Write a line of code that prints parameterVariable to stdout using console.log:
console.log(parameterVariable);
}
Day 0: Data Types Problem : Data Types
My code :
function performOperation(secondInteger, secondDecimal, secondString) {
// Declare a variable named 'firstInteger' and initialize with integer value 4.
const firstInteger = 4;
// Declare a variable named 'firstDecimal' and initialize with floating-point value 4.0.
const firstDecimal = 4.0;
// Declare a variable named 'firstString' and initialize with the string "HackerRank".
const firstString = 'HackerRank ';
console.log(parseInt(firstInteger) + parseInt(secondInteger));
// Write code that uses console.log to print the sum of the 'firstInteger' and 'secondInteger' (converted to a Number type) on a new line.
console.log(parseFloat(firstDecimal) + parseFloat(secondDecimal));
// Write code that uses console.log to print the sum of 'firstDecimal' and 'secondDecimal' (converted to a Number type) on a new line.
console.log(firstString + secondString);
// Write code that uses console.log to print the concatenation of 'firstString' and 'secondString' on a new line. The variable 'firstString' must be printed first.
Day 1: Arithmetic Operators Problem : Arithmetic Operators
My code :
function getArea(length, width) {
let area;
area = length * width;
// Write your code here
return area;
}
/**
* Calculate the perimeter of a rectangle.
*
* length: The length of the rectangle.
* width: The width of the rectangle.
*
* Return a number denoting the perimeter of a rectangle.
**/
function getPerimeter(length, width) {
let perimeter;
perimeter = 2 * (length + width);
// Write your code here
return perimeter;
}
Day 1: Functions Problem : Functions
My code :
/*
* Create the function factorial here
*/
function factorial(n) {
var result = 1;
for (var i=1; i<(n+1); i++) {
result *= i;
}
return result;
}
Day 1: Let and Const Problem : Let and Const
My code :
function main() {
const PI = Math.PI;
// Write your code here. Read input using 'readLine()' and print output using 'console.log()'.
const r = readLine();
console.log(PI * r * r);
// Print the area of the circle:
console.log(2 * r * PI);
// Print the perimeter of the circle:
Day 2: Conditional Statements: If-Else Problem : Conditional Statements: If-Else
My code :
Day 2: Conditional Statements: Switch Problem : Conditional Statements: Switch
My code :
Day 2: LoopsProblem : Loops
My code :
Day 3: Arrays Problem : Arrays
My code :
Day 3: Try, Catch, and Finally Problem : Try, Catch, and Finally
My code :
Day 3: Throw Problem : Throw
My code :
Day 4: Create a Rectangle Object Problem : Create a Rectangle Object
My code :
Day 4: Count Objects Problem : Count Objects
My code :
Day 4: Classes Problem : Classes
My code :
Day 5: Inheritance Problem : Inheritance
My code :
Day 5: Template Literals Problem : Template Literals
My code :
Day 5: Arrow Functions Problem : Arrow Functions
My code :
Day 6: Bitwise Operators Problem : Bitwise Operators
My code :
Day 6: JavaScript Dates Problem : JavaScript Dates
My code :
Day 7: Regular Expressions I Problem : Regular Expressions I
My code :
Day 7: Regular Expressions II Problem : Regular Expressions II
My code :
Day 7: Regular Expressions III Problem : Regular Expressions III
My code :
Day 8: Create a Button Problem : Create a Button
My code :
Day 8: Buttons Container Problem : Buttons Container
My code :
Day 9: Binary Calculator Problem : Binary Calculator
My code :