#01: День 0: Привет, мир!

В этой задаче достаточно просто добавить одну переменную. Пример ниже: →

function greeting(parameterVariable) {
// This line prints 'Hello, World!' to the console:
console.log('Hello, World!\n'+parameterVariable);
}

#02: День 0: Типы данных

Образец ввода 0

12
4.32
is the best place to learn and practice coding!

Пример вывода 0

16
8.32
HackerRank is the best place to learn and practice coding!

Пояснение 0

Когда мы суммируем целые числа и, мы получаем целое число.
Когда мы суммируем числа с плавающей запятой и, мы получаем. Когда мы объединяем HackerRank с is the best place to learn and practice coding!, мы получаем HackerRank is the best place to learn and practice coding!.

Вы не пройдете это испытание, если попытаетесь присвоить значения Sample Case своим переменным вместо того, чтобы следовать приведенным выше инструкциям.

Решение: →

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 ';
// 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(firstInteger+parseInt(secondInteger));
// 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(firstDecimal+parseFloat(secondDecimal));
// 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.
console.log(firstString+secondString);
}

#03: День 1: Арифметические операторы

Образец ввода 0

3
4.5

Пример вывода 0

13.5
15

Пояснение 0

Площадь прямоугольника: длина * ширина = 3*4,5 = 13,5
Периметр прямоугольника. 2*(длина+ширина)=2*(3+4,5)

Решение:

function getArea(length, width) {
let area;
// Write your code here
area = length*width;
return area;
}
function getPerimeter(length, width) {
let perimeter;
// Write your code here
perimeter = 2*(length+width);
return perimeter;
}

#04: День 1: Функции

Образец ввода 0

4

Пример вывода 0

24

Пояснение 0

Возвращаем значение. 4! =4*3*2*1 = 24

Решение:

/*
* Create the function factorial here
*/
function factorial(n){
if(n>0 && n<=1){
return n;
}else{
return n * factorial(n-1);
}}

#05: День 1: Let и Const

Образец ввода 0

2.6

Пример вывода 0

21.237166338267002
16.336281798666924

Пояснение 0

Учитывая радиус, r = 2,5, мы вычисляем следующее:

площадь = pi * r² = 21,2371

периметр = 2*pi*r=16,3362

Затем мы печатаем площадь в качестве первой строки вывода и периметр в качестве второй строки вывода.

Решение:

// Write your code here. Read input using 'readLine()' and print output using 'console.log()'.
const PI = Math.PI;
const number = readLine();
// Print the area of the circle:
console.log(PI*(number*number));
// Print the perimeter of the circle:
console.log(2*PI*number);

#06: День 2: Условные операторы: если-иначе

Образец ввода 0

11

Пример вывода 0

D

Пояснение 0

Поскольку счет = 11, он удовлетворяет условию 10‹ score≤15 (что соответствует D). Таким образом, мы возвращаем D в качестве нашего ответа.

Решение:

function getGrade(score) {
let grade;
// Write your code here
if(score>25 && score<=30){
grade = 'A';
}else if(score>20 && score<=25){
grade ='B';
}else if(score>15 && score<=20){
grade ='C';
}else if(score>10 && score<=15){
grade ='D';
}else if(score>5 && score<=10){
grade ='E';
}else if(score>0 && score<=5){
grade ='F';
}
return grade;
}

#07: День 2: Условные операторы: Switch

Образец ввода 0

adfgt

Пример вывода 0

A

Пояснение 0

Первый символ строки s =adfgt — a. Поскольку данные критерии предусматривают, что мы печатаем A каждый раз, когда первый символ находится в {a,e,i,o,u}, мы возвращаем A в качестве нашего ответа.

Решение:

function getLetter(s) {
let letter;
// Write your code here
const string = [...s];
const firstChar = string[0];
switch(firstChar){
case 'a'||'e'||'i'||'o'||'u':
letter='A';
break;
case 'b'||'c'||'d'||'f'||'g':
letter='B';
break;
case 'h'||'j'||'k'||'l'||'m':
letter='C';
break;
default:
letter='D';
}
return letter;
}

#08: День 2: Петли

Образец ввода 0

javascriptloops

Пример вывода 0

a
a
i
o
o
j
v
s
c
r
p
t
l
p
s

Пояснение 0

Обратите внимание на следующее:

  • Каждая буква печатается с новой строки.
  • Затем гласные печатаются в том же порядке, в каком они появились в s.
  • Затем согласные печатаются в том же порядке, в каком они появились в s.

Решение:

function vowelsAndConsonants(s) {
const array = [...s];
const vowel = [];
const consonant = [];
array.forEach(word=>{
if(word==='a' || word==='e' || word==='i' || word==='o' || word==='u'){
vowel.push(word);
}else{
consonant.push(word);
}
})
const finalWords  =[...vowel,...consonant];
finalWords.map(alphabate=>{
console.log(alphabate);
})
}

#09: День 3: Массивы

Образец ввода 0

5
2 3 6 6 5

Пример вывода 0

5

Пояснение 0

Учитывая массив nums=[2,3,6,6,5], мы видим, что наибольшее значение в массиве равно 6, а второе по величине значение равно 5. Таким образом, мы возвращаем 5 в качестве нашего ответа.

function getSecondLargest(nums) {
// Complete the function
let largest = nums[0];
let secondLargest = nums[0];
for (let i = 1; i < nums.length; i++) {
if (nums[i] > largest) {
secondLargest = largest;
largest = nums[i];
continue;
}
if ((nums[i] > secondLargest) && (nums[i] < largest)) {
secondLargest = nums[i];
}
}
return secondLargest;
}

# 10: День 3: Попробуйте, поймайте и, наконец,

Решение:

function reverseString(s) {
try{
console.log(s.split("").reverse().join(""));
}catch(err){
console.log(err.message)
console.log(s);
}
}

Сегодня больше нет. Если вы хотите узнать больше, поищите в Google и продолжайте учиться. Если я сделаю какие-либо ошибки, пожалуйста, сообщите мне. Я сделаю все возможное, чтобы решить эту проблему. Спасибо всем.