You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Test the example code locally. Try entering different grades, for example, **4.75**, **5.49**, **5.50** and **6.00**. For grades **less than 5.50** the program will not give any output, however for grades of **5.50 or greater**, the output will be "**Excellent!**". The function is called by simply writing its name and filling the input value in the parenthesis:
77
+
Test the example code locally. Try entering different grades, for example, **4.75**, **5.49**, **5.50**, and **6.00**. For grades **less than 5.50** the program will not give any output, however for grades of **5.50 or greater**, the output will be "**Excellent!**". The function is called by simply writing its name and filling the input value in the parenthesis:
Similarly to the example above, we input a grade and check if it is excellent, but this time we should **output a result in both cases**:
103
103
@@ -113,7 +113,7 @@ You can test your solution at the following link: [https://judge.softuni.org/Con
113
113
When we have **only one command** in the body of the **`if` statement**, we can **skip the curly braces**, indicating the body of the conditional operator. When we need to execute a **block of code** (group of commands), curly braces are **mandatory**. In case the braces are omitted, **only the first line of code** will be executed after the **`if` statement**.
<td>It is a good practice to <strong> always include curly braces</strong> since this makes the code more readable, neater and cleaner.</td>
116
+
<td>It is a good practice to <strong> always include curly braces</strong> since this makes the code more readable, neater, and cleaner.</td>
117
117
</tr></table>
118
118
119
119
Here is an example, where omitting the curly braces leads to confusion:
@@ -145,7 +145,7 @@ The problem can be solved with a single **`if-else`** structure and the operator
145
145
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#2](https://judge.softuni.org/Contests/Practice/Index/929#2).
146
146
147
147
148
-
### Problem: Finding The Greater Number
148
+
### Problem: Greater Number
149
149
150
150
Write a program that reads two integers and outputs the greater one.
151
151
@@ -190,7 +190,7 @@ else {
190
190
}
191
191
```
192
192
193
-
### Problem: Numbers One Through 9 in English
193
+
### Problem: Number 0...9 to Text
194
194
195
195
Print the digits one through nine in English on the console (the numbers are passed as arguments of the function upon call). We can take the digit and through a **series of conditions** print the corresponding English word on the console:
196
196
@@ -260,7 +260,7 @@ Please note that for this problem the Judge system is set up to ignore any non-n
260
260
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#5](https://judge.softuni.org/Contests/Practice/Index/929#5).
261
261
262
262
263
-
### Problem: Summing Up Seconds
263
+
### Problem: Sum Seconds
264
264
265
265
Three athletes finish with some **number of seconds** (between **1** and **50**). Write a function that takes the times of the contestants and calculates their **combined time** in **minutes:seconds** format. Seconds are to be printed with a **leading zero** (2 -> "02", 7 -> "07", 35 -> "35").
266
266
@@ -341,173 +341,7 @@ To date, we have written quite a lot of code and oftentimes there were mistakes,
341
341
342
342
We add a point, at which our function will stop its execution - a **breakpoint** after which we start the program in **debug mode** through pressing [**F5**]. The program will follow its course until it reaches our interrupt (**breakpoint**). After which we the execution can proceed to the **next line of code** by pressing [**F10**].
343
343
344
-
## Exercises: Simple Conditions
345
-
346
-
Now let's practice the lessons learned in this chapter with a few practical exercises.
347
-
348
-
### Empty Visual Studio Code file
349
-
350
-
We start Visual Studio Code and create a new file [**File**] -> [**New File**]:
After that, we will see a new file, which is anonymous for the moment to our system. To be recognized correctly, we need to save our code as a **JavaScript** file: [**File**] -> [**Save**]:
The first exercise for this topic is to write a **JavaScript function**, which **takes a grade** (decimal number) and prints "**Excellent!**", if the grade is **5.50** or higher.
366
-
367
-
#### Sample Input and Output
368
-
369
-
| Input | Output |
370
-
| --- | ---- |
371
-
| 6 | Excellent! |
372
-
| 5 | (no output) |
373
-
| 5.5 | Excellent! |
374
-
| 5.49 | (no output) |
375
-
376
-
#### Hints and Pointers
377
-
378
-
We create a **new anonymous file** by clicking [**File**] -> [**New File**]. Then we save it ([**File**] -> [**Save**]), as a **JavaScript file**, with the file extension **.js**
379
-
380
-
Now that we have prepared a JavaScript file, we have to solve the problem. To this effect we write the following code:
The next exercise for this topic is to write a **JavaScript function**, which **takes a grade** (decimal number) and prints "**Excellent!**", if the grade is **5.50** or higher, or “**Not excellent.**” if it is not.
406
-
407
-
#### Sample Input and Output
408
-
409
-
| Input | Output |
410
-
| --- | ---- |
411
-
| 6 | Excellent! |
412
-
| 5 | Not excellent. |
413
-
| 5.5 | Excellent! |
414
-
| 5.49 | Not excellent. |
415
-
416
-
#### Hints and Pointers
417
-
418
-
Firstly we create a **new JavaScript file**. After that, we **write the code** of the program. You may use the following example code as a hint:
Write a function that checks whether an **integer** input is either **even** or **odd** and prints the result on the console.
438
-
439
-
#### Sample Input and Output
440
-
441
-
| Input | Output |
442
-
| --- | ---- |
443
-
| 2 | even |
444
-
| 3 | odd |
445
-
| 25 | odd |
446
-
| 1024 | even |
447
-
448
-
#### Hints and Pointers
449
-
450
-
Again firstly we must create a **new JavaScript file**. Then the check if a number is either even or odd can be made with the operator **`%`**, which will return the **remainder from an integer divided by 2** as follows: **`let isEven = (num % 2 == 0)`**.
451
-
452
-
Now we have to **start** the program with [**Ctrl+F5**] and test it:
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#2](https://judge.softuni.org/Contests/Practice/Index/929#2).
459
-
460
-
461
-
### Problem: Find The Greater Number
462
-
463
-
Write a function that takes **two integers** and prints the bigger one on the console.
464
-
465
-
#### Sample Input and Output
466
-
467
-
| Input | Output |
468
-
|-----|------|
469
-
|5<br>3| 5 |
470
-
|3<br>5| 5 |
471
-
|10<br>10| 10 |
472
-
|-5<br>5| 5 |
473
-
474
-
#### Hints and pointers
475
-
476
-
As usual, first, we need to create a **new JavaScript file**. For the main logic, we need a single **`if-else`** construct. The code below is deliberately blurred, however, there is enough visible to give you some hint, so you can complete it yourself:
When we are done with the implementation of the solution, we call the function and pass it example parameters, we **run** the program with [**Ctrl+F5**] and test it:
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#3](https://judge.softuni.org/Contests/Practice/Index/929#3).
486
-
487
-
488
-
### Problem: Output a Digit's Word Equivalent
489
-
490
-
Write a function that takes an **integer in the range**[**0 … 9**] and prints **its word equivalent** in English. If the number is outside the given range, the function should return “**number too big**”.
491
-
492
-
#### Sample Input and Output
493
-
494
-
| Input | Output |
495
-
| --- | ---- |
496
-
| 5 | five |
497
-
| 1 | one |
498
-
| 9 | nine |
499
-
| 10 | number too big |
500
-
501
-
#### Hints and Pointers
502
-
503
-
We can use a sequence of **`if-else`** statements to cover every one of the possible **11 cases**.
504
-
505
-
#### Testing in The Judge System
506
-
507
-
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#4](https://judge.softuni.org/Contests/Practice/Index/929#4).
508
-
509
-
510
-
### Problem: Guess the Password
344
+
### Problem: Password Guess
511
345
512
346
Write a function that **accepts a password** (one line of random text) and checks if the input **matches** the phrase “**s3cr3t!P@ssw0rd**”. If it matches, print “**Welcome**”, otherwise print “**Wrong password!**”.
513
347
@@ -528,9 +362,9 @@ Use an **`if-else`** statement.
528
362
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#8](https://judge.softuni.org/Contests/Practice/Index/929#8).
529
363
530
364
531
-
### Problem: Numbers from 100 to 200
365
+
### Problem: Number 100...200
532
366
533
-
Write a function that **accepts an integer** as a parameter and checks if it is **below 100**, **between 100 and 200** or **over 200**. Print the appropriate messages as per the examples below.
367
+
Write a function that **accepts an integer** as a parameter and checks if it is **below 100**, **between 100 and 200**, or **over 200**. Print the appropriate messages as per the examples below.
534
368
535
369
#### Sample Input and Output
536
370
@@ -545,7 +379,7 @@ Write a function that **accepts an integer** as a parameter and checks if it is
545
379
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#9](https://judge.softuni.org/Contests/Practice/Index/929#9).
546
380
547
381
548
-
### Problem: Identical Words
382
+
### Problem: Equal Words
549
383
550
384
551
385
Write a function that **accepts two words** as parameters and checks if they are the same. A comparison should be case-insensitive and the output should be either “**yes**” or “**no**”.
@@ -569,7 +403,7 @@ Before the comparison, both words should be in lower case, so that case (upperca
569
403
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#10](https://judge.softuni.org/Contests/Practice/Index/929#10).
570
404
571
405
572
-
### Problem: Speed Assessment
406
+
### Problem: Speed Info
573
407
574
408
Write a function, that **takes speed** (decimal number) as a parameter and prints **speed information**. For speeds **up to 10** (inclusive), print "**slow**". For speed **over 10** and **up to 50**, print "**average**". For speeds **over 50** and **up to 150**, print "**fast**". For speeds **over 150** and **up to 1000**, print "**ultra fast**". For higher speed, print "**extremely fast**".
575
409
@@ -596,7 +430,7 @@ The first argument of the function is the type of shape (**`square`**, **`rectan
596
430
* If the shape is a **square**, the next argument will be one number - the length of its side.
597
431
* If the shape is a **rectangle**, the next argument will be two numbers - the lengths of its sides.
598
432
* If the shape is a **circle**, the next argument will be one number - the radius of the circle.
599
-
* If the shape is a **triangle**, the next argument will be two numbers - its base and the corresponding altitude.
433
+
* If the shape is a **triangle**, the next argument will be two numbers - base and the corresponding altitude.
600
434
601
435
The result should be rounded up to the **third decimal point**.
602
436
@@ -637,7 +471,7 @@ Add 15 minutes and check using a set of conditions. If minutes are over 59 **inc
637
471
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#13](https://judge.softuni.org/Contests/Practice/Index/929#13).
638
472
639
473
640
-
### Problem: Tree Equal Numbers
474
+
### Problem: 3 Equal Numbers
641
475
642
476
Write a function that takes **3 numbers** as arguments and prints whether they are the same (**yes** / **no**).
643
477
@@ -654,7 +488,7 @@ Write a function that takes **3 numbers** as arguments and prints whether they a
654
488
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#14](https://judge.softuni.org/Contests/Practice/Index/929#14).
655
489
656
490
657
-
### Problem: \*Convert a Number to Words
491
+
### Problem: Number 0...100 to Text
658
492
659
493
Write a function that converts numbers in the range of [**0 … 100**] in text.
660
494
@@ -679,13 +513,13 @@ Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/929#
679
513
680
514
Now since we have completed a few exercises on **conditional statements (checks)**, let's do something a bit more interesting: an application with a Graphical User Interface (GUI) for currency conversion. We will employ the knowledge from this chapter to select from the different available currencies and make calculations as per the appropriate exchange rates for the given currency.
681
515
682
-
### Problem: \*\*Currency Converter
516
+
### Problem: \*\*Currency Converter
683
517
684
518
Now let's see how to create a graphical (**GUI**) application for **currency conversion**. The application will look similar to the picture below:
For visualization, we will use an **internet browser**, that interprets **HTML** pages. We will create a new page and will build the **structure**, **appearance** and **functionality** of our application.
522
+
For visualization, we will use an **internet browser**, that interprets **HTML** pages. We will create a new page and will build the **structure**, **appearance**, and **functionality** of our application.
689
523
690
524
As usual, we **create a new file**, save it with the name **Currency-Converter**, however this time we add the file extension **.html**.
0 commit comments