Skip to main content

Day 0: Data Types

 Objective

Today, we're discussing data types. Check out the attached tutorial for more details.

Task

Variables named , and  are declared for you in the editor below. You must use the  operator to perform the following sequence of operations:

  1. Convert  to an integer (Number type), then sum it with  and print the result on a new line using console.log.
  2. Convert  to a floating-point number (Number type), then sum it with  and print the result on a new line using console.log.
  3. Print the concatenation of  and  on a new line using console.log. Note that  must be printed first.

Input Format

Data TypeParameterDescription
stringThe string representation of an integer you must sum with .
stringThe string representation of a floating-point number you must sum with .
stringA string of one or more space-separated words you must append to .

Output Format

Print the following three lines of output:

  1. On the first line, print the sum of  and the integer representation of .
  2. On the second line, print the sum of  and the floating-point representation of .
  3. On the third line, print  concatenated with . You must print  before .

Sample Input 0

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

Sample Output 0

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

Explanation 0

When we sum the integers  and , we get the integer .
When we sum the floating-point numbers  and , we get . When we concatenate HackerRank with is the best place to learn and practice coding!, we get HackerRank is the best place to learn and practice coding!.

You will not pass this challenge if you attempt to assign the Sample Case values to your variables instead of following the instructions above.


Solution



function performOperation(secondInteger, secondDecimal, secondString) {
    // Declare a variable named 'firstInteger' and initialize with integer value 4.
    var firstInteger = 4;
    
    // Declare a variable named 'firstDecimal' and initialize with floating-point value 4.0.
    var firstDecimal = 4.0;
    
    // Declare a variable named 'firstString' and initialize with the string "HackerRank".
    var 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.
    var sum =(firstInteger) +parseInt(secondInteger);

    console.log(sum);
    
    // Write code that uses console.log to print the sum of 'firstDecimal' and 'secondDecimal' (converted to a Number            type) on a new line.
    var sum2 = (firstDecimal) + parseFloat(secondDecimal);
    console.log(sum2);
    
    // 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);
}

Comments

Popular posts from this blog

Day 2: Conditional Statements: Switch

  Objective In this challenge, we learn about  switch statements . Check out the attached tutorial for more details. Task Complete the  getLetter(s)  function in the editor. It has one parameter: a string,  , consisting of lowercase English alphabetic letters (i.e.,  a  through  z ). It must return  A ,  B ,  C , or  D  depending on the following criteria: If the first character in string   is in the set  , then return  A . If the first character in string   is in the set  , then return  B . If the first character in string   is in the set  , then return  C . If the first character in string   is in the set  , then return  D . Hint:  You can get the letter at some index   in   using the syntax  s[i]  or  s.charAt(i) . Input Format Stub code in the editor reads a single string denoting   from ...

Day 2: Conditional Statements: If-Else

Day 2: Conditional Statements: If-Else || Hackerrank Solution Objective In this challenge, we learn about  if-else  statements. Check out the attached tutorial for more details. Task Complete the  getGrade(score)  function in the editor. It has one parameter: an integer,  , denoting the number of points Julia earned on an exam. It must return the letter corresponding to her   according to the following rules: If  , then  . If  , then  . If  , then  . If  , then  . If  , then  . If  , then  .

Jumping on the Clouds Hackerrank

Jumping on the Clouds solutions in c. Emma is playing a new mobile game that starts with consecutively numbered clouds. Some of the clouds are thunderheads and others are cumulus. She can jump on any cumulus cloud having a number that is equal to the number of the current cloud plus 1  or 2  . She must avoid the thunderheads. Determine the minimum number of jumps it will take Emma to jump from her starting position to the last cloud. It is always possible to win the game. For each game, Emma will get an array of clouds numbered 0   if they are safe or 1 if they must be avoided. For example, c=[0,1,0,0,0,1,0] indexed from 0....6. The number on each cloud is its index in the list so she must avoid the clouds at indexes 1 and 5 . She could follow the following two paths:0 ➜ 2 ➜ 4➜6   or 0 ➜ 2 ➜ 3 ➜ 4 ➜ 6 . The first path takes 3   jumps while the second takes 4 . Function Description Complete the  jumpingOnClouds ...