Skip to content

Commit e103480

Browse files
authored and
committed
Added rest of Day 7 challenges
1 parent 1b59a29 commit e103480

22 files changed

+391
-362
lines changed

Day 0/Data Types.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
/**
2-
* The variables 'firstInteger', 'firstDecimal', and 'firstString' are declared for you -- do not modify them.
3-
* Print three lines:
4-
* 1. The sum of 'firstInteger' and the Number representation of 'secondInteger'.
5-
* 2. The sum of 'firstDecimal' and the Number representation of 'secondDecimal'.
6-
* 3. The concatenation of 'firstString' and 'secondString' ('firstString' must be first).
7-
*
8-
* Parameter(s):
9-
* secondInteger - The string representation of an integer.
10-
* secondDecimal - The string representation of a floating-point number.
11-
* secondString - A string consisting of one or more space-separated words.
12-
**/
13-
function performOperation(secondInteger, secondDecimal, secondString) {
14-
// Declare a variable named 'firstInteger' and initialize with integer value 4.
15-
const firstInteger = 4;
16-
17-
// Declare a variable named 'firstDecimal' and initialize with floating-point value 4.0.
18-
const firstDecimal = 4.0;
19-
20-
// Declare a variable named 'firstString' and initialize with the string "HackerRank".
21-
const firstString = 'HackerRank ';
22-
23-
// Write code that uses console.log to print the sum of the 'firstInteger' and 'secondInteger' (converted to a Number type) on a new line.
24-
console.log(firstInteger + Number(secondInteger));
25-
26-
27-
// Write code that uses console.log to print the sum of 'firstDecimal' and 'secondDecimal' (converted to a Number type) on a new line.
28-
console.log(firstDecimal + Number(secondDecimal));
29-
30-
31-
// 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.
32-
33-
console.log(firstString.concat(secondString));
34-
1+
/**
2+
* The variables 'firstInteger', 'firstDecimal', and 'firstString' are declared for you -- do not modify them.
3+
* Print three lines:
4+
* 1. The sum of 'firstInteger' and the Number representation of 'secondInteger'.
5+
* 2. The sum of 'firstDecimal' and the Number representation of 'secondDecimal'.
6+
* 3. The concatenation of 'firstString' and 'secondString' ('firstString' must be first).
7+
*
8+
* Parameter(s):
9+
* secondInteger - The string representation of an integer.
10+
* secondDecimal - The string representation of a floating-point number.
11+
* secondString - A string consisting of one or more space-separated words.
12+
**/
13+
function performOperation(secondInteger, secondDecimal, secondString) {
14+
// Declare a variable named 'firstInteger' and initialize with integer value 4.
15+
const firstInteger = 4;
16+
17+
// Declare a variable named 'firstDecimal' and initialize with floating-point value 4.0.
18+
const firstDecimal = 4.0;
19+
20+
// Declare a variable named 'firstString' and initialize with the string "HackerRank".
21+
const firstString = 'HackerRank ';
22+
23+
// Write code that uses console.log to print the sum of the 'firstInteger' and 'secondInteger' (converted to a Number type) on a new line.
24+
console.log(firstInteger + Number(secondInteger));
25+
26+
27+
// Write code that uses console.log to print the sum of 'firstDecimal' and 'secondDecimal' (converted to a Number type) on a new line.
28+
console.log(firstDecimal + Number(secondDecimal));
29+
30+
31+
// 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.
32+
33+
console.log(firstString.concat(secondString));
34+
3535
}

Day 0/Hello World.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
/**
2-
* A line of code that prints "Hello, World!" on a new line is provided in the editor.
3-
* Write a second line of code that prints the contents of 'parameterVariable' on a new line.
4-
*
5-
* Parameter:
6-
* parameterVariable - A string of text.
7-
**/
8-
function greeting(parameterVariable) {
9-
// This line prints 'Hello, World!' to the console:
10-
console.log('Hello, World!');
11-
console.log(parameterVariable);
12-
13-
// Write a line of code that prints parameterVariable to stdout using console.log:
14-
1+
/**
2+
* A line of code that prints "Hello, World!" on a new line is provided in the editor.
3+
* Write a second line of code that prints the contents of 'parameterVariable' on a new line.
4+
*
5+
* Parameter:
6+
* parameterVariable - A string of text.
7+
**/
8+
function greeting(parameterVariable) {
9+
// This line prints 'Hello, World!' to the console:
10+
console.log('Hello, World!');
11+
console.log(parameterVariable);
12+
13+
// Write a line of code that prints parameterVariable to stdout using console.log:
14+
1515
}

Day 1/Arithmetic Operators.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
/**
2-
* Calculate the area of a rectangle.
3-
*
4-
* length: The length of the rectangle.
5-
* width: The width of the rectangle.
6-
*
7-
* Return a number denoting the rectangle's area.
8-
**/
9-
function getArea(length, width) {
10-
let area;
11-
// Write your code here
12-
area = length * width;
13-
return area;
14-
}
15-
16-
/**
17-
* Calculate the perimeter of a rectangle.
18-
*
19-
* length: The length of the rectangle.
20-
* width: The width of the rectangle.
21-
*
22-
* Return a number denoting the perimeter of a rectangle.
23-
**/
24-
function getPerimeter(length, width) {
25-
let perimeter;
26-
// Write your code here
27-
perimeter = 2 * (length + width);
28-
return perimeter;
1+
/**
2+
* Calculate the area of a rectangle.
3+
*
4+
* length: The length of the rectangle.
5+
* width: The width of the rectangle.
6+
*
7+
* Return a number denoting the rectangle's area.
8+
**/
9+
function getArea(length, width) {
10+
let area;
11+
// Write your code here
12+
area = length * width;
13+
return area;
14+
}
15+
16+
/**
17+
* Calculate the perimeter of a rectangle.
18+
*
19+
* length: The length of the rectangle.
20+
* width: The width of the rectangle.
21+
*
22+
* Return a number denoting the perimeter of a rectangle.
23+
**/
24+
function getPerimeter(length, width) {
25+
let perimeter;
26+
// Write your code here
27+
perimeter = 2 * (length + width);
28+
return perimeter;
2929
}

Day 1/Functions.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
2-
/*
3-
* Create the function factorial here
4-
*/
5-
function factorial(n)
6-
{
7-
if (n < 2)
8-
{
9-
return 1;
10-
}
11-
12-
return n * factorial(n-1);
1+
2+
/*
3+
* Create the function factorial here
4+
*/
5+
function factorial(n)
6+
{
7+
if (n < 2)
8+
{
9+
return 1;
10+
}
11+
12+
return n * factorial(n-1);
1313
}

Day 1/Let and Const.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
function main() {
2-
// Write your code here. Read input using 'readLine()' and print output using 'console.log()'.
3-
const PI = Math.PI;
4-
var r = parseInt(readLine());
5-
// Print the area of the circle:
6-
var area = PI * r * r;
7-
console.log(area);
8-
9-
// Print the perimeter of the circle:
10-
var perimeter = 2 * PI * r;
11-
console.log(perimeter);
1+
function main() {
2+
// Write your code here. Read input using 'readLine()' and print output using 'console.log()'.
3+
const PI = Math.PI;
4+
var r = parseInt(readLine());
5+
// Print the area of the circle:
6+
var area = PI * r * r;
7+
console.log(area);
8+
9+
// Print the perimeter of the circle:
10+
var perimeter = 2 * PI * r;
11+
console.log(perimeter);
1212

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
function getGrade(score)
2-
{
3-
let grade;
4-
// Write your code here
5-
6-
if ((score > 25) && (score <= 30))
7-
{
8-
grade = 'A';
9-
}
10-
11-
else if ((score > 20) && (score <= 25))
12-
{
13-
grade = 'B';
14-
}
15-
16-
else if ((score > 15) && (score <= 20))
17-
{
18-
grade = 'C';
19-
}
20-
21-
else if ((score > 10) && (score <= 15))
22-
{
23-
grade = 'D';
24-
}
25-
26-
else if ((score > 5) && (score <= 10))
27-
{
28-
grade = 'E';
29-
}
30-
31-
else if ((score > 0) && (score <= 5))
32-
{
33-
grade = 'F';
34-
}
35-
36-
return grade;
1+
function getGrade(score)
2+
{
3+
let grade;
4+
// Write your code here
5+
6+
if ((score > 25) && (score <= 30))
7+
{
8+
grade = 'A';
9+
}
10+
11+
else if ((score > 20) && (score <= 25))
12+
{
13+
grade = 'B';
14+
}
15+
16+
else if ((score > 15) && (score <= 20))
17+
{
18+
grade = 'C';
19+
}
20+
21+
else if ((score > 10) && (score <= 15))
22+
{
23+
grade = 'D';
24+
}
25+
26+
else if ((score > 5) && (score <= 10))
27+
{
28+
grade = 'E';
29+
}
30+
31+
else if ((score > 0) && (score <= 5))
32+
{
33+
grade = 'F';
34+
}
35+
36+
return grade;
3737
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
function getLetter(s) {
2-
let letter;
3-
// Write your code here
4-
5-
switch (s.charAt(0))
6-
{
7-
case ( 'a' || 'e' || 'o' || 'i' || u):
8-
letter = 'A';
9-
break;
10-
11-
case ('b' || 'c' || 'd' || 'f' || 'g'):
12-
letter = 'B';
13-
break;
14-
15-
case ('h' || 'j' || 'k' || 'l' || 'm'):
16-
letter = 'C';
17-
break;
18-
19-
case ('z' || 'n' || 'p' || 'q' || 'r' || 's' || 't' || 'v' || 'w' || 'x' || 'y' ):
20-
letter = 'D';
21-
22-
}
23-
24-
25-
return letter;
1+
function getLetter(s) {
2+
let letter;
3+
// Write your code here
4+
5+
switch (s.charAt(0))
6+
{
7+
case ( 'a' || 'e' || 'o' || 'i' || u):
8+
letter = 'A';
9+
break;
10+
11+
case ('b' || 'c' || 'd' || 'f' || 'g'):
12+
letter = 'B';
13+
break;
14+
15+
case ('h' || 'j' || 'k' || 'l' || 'm'):
16+
letter = 'C';
17+
break;
18+
19+
case ('z' || 'n' || 'p' || 'q' || 'r' || 's' || 't' || 'v' || 'w' || 'x' || 'y' ):
20+
letter = 'D';
21+
22+
}
23+
24+
25+
return letter;
2626
}

Day 2/Loops.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
/*
2-
* Complete the vowelsAndConsonants function.
3-
* Print your output using 'console.log()'.
4-
*/
5-
function vowelsAndConsonants(s)
6-
{
7-
var vowels = ['a', 'e', 'i', 'o', 'u']
8-
for (var i = 0; i < s.length; i++)
9-
{
10-
if (vowels.indexOf(s[i]) > -1)
11-
{
12-
console.log(s[i]);
13-
}
14-
}
15-
16-
for (var j = 0; j < s.length; j++)
17-
{
18-
if (vowels.indexOf(s[j]) < 0)
19-
{
20-
console.log(s[j]);
21-
}
22-
}
23-
1+
/*
2+
* Complete the vowelsAndConsonants function.
3+
* Print your output using 'console.log()'.
4+
*/
5+
function vowelsAndConsonants(s)
6+
{
7+
var vowels = ['a', 'e', 'i', 'o', 'u']
8+
for (var i = 0; i < s.length; i++)
9+
{
10+
if (vowels.indexOf(s[i]) > -1)
11+
{
12+
console.log(s[i]);
13+
}
14+
}
15+
16+
for (var j = 0; j < s.length; j++)
17+
{
18+
if (vowels.indexOf(s[j]) < 0)
19+
{
20+
console.log(s[j]);
21+
}
22+
}
23+
2424
}

0 commit comments

Comments
 (0)