---
# System prepended metadata

title: Exercises for Session 1

---

# Exercises for Session 1

1. Rewrite the following `switch` statement using `if` and `else`:

```javascript
switch (figureToDraw) {
  case "square":
    drawSquare();
    break;

  case "circle":
    drawCircle();
    break;

  case "triangle":
    drawTriangle();
    break;

  default:
    drawLine();
}
```

2. Write a `try ... catch` block that throws an error with the message "Hello world error message".

3. Rewrite the following `do ... while` using a regular `while`:

```javascript
const n = 10;
let i = 0;

do {
  console.log(i);
  i++;
} while (i < n);
```

4. Write a `while` loop that logs the first ten negative integers.

5. Rewrite the following `do ... while` using a regular `for`:

```javascript
const n = 10;
let i = 0;

do {
  console.log(i);
  i++;
} while (i < n);
```

6. Log the first 10 even natural numbers.

7. Log the first 10 natural numbers that are divisible by both 2 and 3.

8. Write a `for` loop that logs the first 10 odd natural numbers excluding the multiples of 3.

9. Modify the code of the previous exercise so that you can log the second number in the sequece using a statement that gets executed outside of the loop.

10. Given variables `a`, `b`, and `operation` where `a` and `b` are numbers and `operation` is a string, write a `switch` statement where each case corresponds to a valid operation between numbers and logs the result to the console.

11. Modify the code of the previous exercise to display exactly 3 decimal digits in the result.

12. Given:

```javascript
let firstName = "John";
let lastName = "Doe";
let city = "denver";
let job = "Developer     ";
```

write the necessary code so that the message "My name is JOHN DOE, I'm from Denver and I work as a developer" gets logged, using the variables declared and initialized above.

13. Determine if the letters "n", "N" and "o" are present in the variables given above and log the results to the console.

14. In JavaScript, it's a common convention to use uppercase letters and [snake case](https://en.wikipedia.org/wiki/Snake_case) to declare important constants (e.g. configuration values). Make the string "database url" comply to this convention.
