Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, 10 Days Of JavaScript. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Day 3: Throw in JavaScript-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To JavaScript
JavaScript is a lightweight, cross-platform, and interpreted scripting language. It is well-known for the development of web pages, many non-browser environments also use it. JavaScript can be used for Client-side developments as well as Server-side developments. JavaScript contains a standard library of objects, like Array, Date, and Math, and a core set of language elements like operators, control structures, and statements.
Advantages of JavaScript
The merits of using JavaScript are −
- Less server interaction − You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
- Immediate feedback to the visitors − They don’t have to wait for a page reload to see if they have forgotten to enter something.
- Increased interactivity − You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
- Richer interfaces − You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.
Link for the Problem – Day 3: Throw – Hacker Rank Solution
Day 3: Throw – Hacker Rank Solution
Problem:
Objective
In this challenge, we practice using throw and catch statements to work with custom error messages.
Task
Complete the isPositive function below. It has one integer parameter, . If the value of is positive, it must return the string YES
. Otherwise, it must throw an Error according to the following rules:
- If is , throw an Error with
Zero Error
. - If is negative, throw an Error with
Negative Error
.
Input Format
Locked stub code in the editor reads the following input from stdin and passes each value of to the function as an argument:
The first line is an integer, , denoting the number of times the function will be called with some .
Each line of the subsequent lines contains an integer denoting some .
Constraints
Output Format
If the value of is positive, the function must return the string YES
. Otherwise, it must throw an Error according to the following rules:
- If is , throw an Error with
Zero Error
. - If is negative, throw an Error with
Negative Error
.
Sample Input 0
3 1 2 3
Sample Output 0
YES YES YES
Explanation 0
Each of the given values is positive, so we return YES
each time. The value returned during each function call is printed on a new line by locked stub code in the editor.
Sample Input 1
3 2 0 6
Sample Output 1
YES Zero Error YES
Explanation 1
Locked stub code in the editor makes the following three calls to the isPositive function:
isPositive(2)
: This returnsYES
because is positive.isPositive(0)
: Because , we throw an Error withZero Error
. This is caught by the locked stub code and the value of its is printed.isPositive(6)
: This returnsYES
because is positive.
Sample Input 2
2 -1 20
Sample Output 2
Negative Error YES
Explanation 2
Locked stub code in the editor makes the following two calls to the isPositive function:
isPositive(-1)
: Because , we throw an Error withNegative Error
. This is caught by the locked stub code and the value of its is printed.isPositive(20)
: This returnsYES
because is positive.
Day 3: Throw – Hacker Rank Solution
function isPositive(a) { if (a === 0) { throw Error("Zero Error"); } if (a < 0) { throw Error("Negative Error"); } return "YES"; }
cheap cialis tadalafil 10mg sale cheap erectile dysfunction pills online
buy cefadroxil 500mg pill buy cefadroxil 250mg propecia 1mg canada
buy diflucan 200mg generic order generic diflucan 200mg buy ciprofloxacin pills for sale
order metronidazole 400mg without prescription buy generic metronidazole buy cephalexin without prescription
generic estradiol 1mg order lamictal 200mg online cheap purchase prazosin sale
cleocin 150mg pill order cleocin 300mg online cheap buy fildena 50mg sale
vermox 100mg ca mebendazole online buy tadalis 10mg cost
purchase nolvadex generic buy cefuroxime medication order ceftin online
avana 200mg sale order tadacip 10mg generic purchase diclofenac without prescription
indocin 50mg pill order lamisil 250mg generic buy suprax without a prescription
order bimatoprost online cheap order trazodone 100mg online desyrel pills
buy generic amoxicillin over the counter buy generic biaxin 500mg buy generic clarithromycin 500mg
suhagra 50mg oral female viagra sildenafil sildenafil 100mg england
clonidine 0.1mg tablet how to get antivert without a prescription spiriva drug
minocycline 100mg for sale buy generic minocin for sale actos 30mg generic
absorica order order amoxicillin 250mg generic zithromax 500mg sale
how to get arava without a prescription arava over the counter order azulfidine without prescription
buy azipro 500mg without prescription buy cheap generic azithromycin buy gabapentin 800mg
tadalafil 10mg uk buy cialis 40mg tadalafil 20mg us
buy lasix 40mg online lasix 100mg sale albuterol for sale online
ivermectin 2mg online buy stromectol 6mg order prednisone 20mg generic
levitra usa order hydroxychloroquine 400mg online cheap hydroxychloroquine drug
vardenafil 20mg over the counter levitra 10mg ca purchase plaquenil online
olmesartan us buy calan paypal oral divalproex 250mg
clobetasol sale purchase buspar generic order cordarone sale
carvedilol generic buy aralen no prescription chloroquine oral
buy diamox 250 mg sale acetazolamide order online buy generic imuran 25mg
order digoxin 250mg without prescription order telmisartan 20mg sale purchase molnupiravir without prescription
naprosyn 250mg us order naproxen 250mg for sale buy prevacid 30mg
albuterol 100 mcg pills order phenazopyridine 200mg pills pyridium over the counter
adalat 10mg brand aceon pills buy fexofenadine 180mg generic
brand amlodipine 10mg norvasc over the counter buy omeprazole tablets