bebekutya

variable exercises js

May 14th, 2023
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.64 KB | Source Code | 0 0
  1.  
  2. Exercise 1:
  3. Create a variable called `name` and assign it your name as a string. Then, write a line of code to log the value of `name` to the console.
  4.  
  5. let myName = "Rozi";
  6. console.log(myName);
  7.  
  8. Exercise 2:
  9. Create two variables called `num1` and `num2` and assign them any numeric values of your choice. Then, calculate the sum of the two numbers and assign it to a new variable called `sum`. Finally, log the value of `sum` to the console.
  10.  
  11. let num1 = 7;
  12. let num2 = 3;
  13. let sum = num1+num2;
  14. console.log(sum);
  15.  
  16. Exercise 3:
  17. Create a variable called `message` and assign it an empty string. Then, concatenate the strings "Hello," and " how are you?" to the `message` variable. Log the final message to the console.
  18.  
  19. let message = ""; // this is an empty string
  20. message = "Hello, " + "how are you?";
  21. console.log(message);
  22.  
  23. Exercise 4:
  24. Create a variable called `radius` and assign it a numeric value representing the radius of a circle. Calculate the circumference of the circle (2 * π * radius) and assign it to a new variable called `circumference`. Log the value of `circumference` to the console.
  25.  
  26. let radius = 5,55;
  27. let circumference = 2*3.14159265359*radius;
  28. console.log(circumference);
  29.  
  30. Exercise 5:
  31. Create a variable called `isRaining` and assign it a boolean value of `true` or `false`, depending on the current weather condition. Use an `if` statement to check if it's raining. If it is, log "Remember to take your umbrella!" to the console. If it's not raining, log "Enjoy the sunny day!".
  32.  
  33. let isRaining = 'true';
  34.  
  35. if isRaining === 'true' {
  36.     console.log(Remember to take your umbrella!");
  37. } else {
  38.     console.log(Enjoy the sunny day!);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment