Getting started with conditionals – HackerRank Solution

In this post, we will solve Getting started with conditionals HackerRank Solution. This problem (Getting started with conditionals) is a part of Linux Shell series.

Task

Read in one character from STDIN.
If the character is ‘Y’ or ‘y’ display “YES”.
If the character is ‘N’ or ‘n’ display “NO”.
No other character will be provided as input.

Input Format

One character

Constraints

The character will be from the set {yYnN}.

Output Format

echo YES or NO to STDOUT.

Sample Input

y  

Sample Output

YES

Solution – Getting started with conditionals – HackerRank Solution

#!/bin/bash
read word
if [[($word == 'y') || ($word == 'Y')]]
then
    echo "YES"
        elif [[($word == 'n') || ($word == 'N')]]
        then
        echo "NO"
fi

Note: This problem (Getting started with conditionals) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *