JavaScript Week 4 excercises

Level 1:
  1. Create a variable called title with a value e.g. "Mr.", or "Ms." (string)
  2. Create a variable called name with a name
  3. Use console.log to print the title plus the name (using +), with a space after the title.
Level 2:
 
  1. Create a variable called year with value 2023 (number)
  2. Create a variable called ageAtEndOfYear with your age at the end of the year
  3. Create a variable called birthYear with value year - ageAtEndOfYear
  4. Use console.log to print your birthYear
Level 3:
 
  1. Create a function called songOfTheDay, it should have 0 parameters
  2. The function should use console.log to print a name of a song
  3. Call the function
Level 4:
 
  1. Create a variable called pi, with value 3.14.
  2. Create a function called circleCircumference which takes 1 parameter called radius.
  3. It should use console.log to show the circle's circumference. (Hint: circle circumference is 2 * pi * radius)
  4. Call the function two times, with different values.
Level 5:
 
  1. Create a function called join, which takes 2 parameters called first and second
  2. The function should use console.log to print adding the two variables together (using +)
  3. Call the function with 2 strings
  4. Call the function with 1 string and 1 number
  5. Call the function with 2 numbers
Level 6:

  1. Create a function called getDayOfMonth which returns which day of the month it is. (a number)
  2. Create a function called getMonthName which returns which month of the year it is. (a string)
  3. Call getDayOfMonth, store the result in a variable called day
  4. Call getMonthName, store the result in a variable called month
  5. Use console.log to print, example: "Today is 10th of May" (use the 2 variables day and month)
Level 7:
 
  1. Create a variable (number) called budget, with the value 200.
  2. Create a function called calculateVenueCost, which takes 1 parameter numPeople.
  3. For each person, the cost is 50. The function should ruturn a number - the total cost for all people (numPeople)
  4. Call the function, store the result in a variable called cost
  5. Use console.log to print the how much money you will have left in your budget.
Level 8:
 
  1. Create a variable called book, it should be an object, with variables name (string), author (string), and numPages (number).
  2. Give each of the variables a value in the object.
  3. Use console.log to print each variable in the object.
Level 9:
 
  1. Create a function called createBook, with 0 parameters.
  2. It should return the same book object from the previous excercise. (an *object*, with variables *name* (string), *author* (string), and *numPages* (number))
  3. Call the function, and save the result in a variable called myBook.
  4. Use console.log to pring myBook to the screen.
Then: change the function to take 1 parameter bookName, and let the name of the book be equal to bookName. Call your function (with a string for the 1st parameter).
Level 10:
 
Use this HTML:
<input type="button" value="Click here" id="btn">
 
1. Create a function in JavaScript called btnClicked which has 0 parameters
1a. Let the function just console.log "clicked"
2. Add an onclick="" attribute to the button, and call your function in the quotes
3. Make sure your button works - it should print "clicked" in the console when you click it
4. Update your btnClicked function to change the background colour of the button
5. Add another button, with a different id, underneath your first button
6. Create a new function called secondBtnClicked
7. In HTML, let the onclick of your new button call the function secondBtnClicked. The function should change the background colour of the second button.
Level 11:
 
Use this HTML
<input type="button" value="Click here" id="btn">
<input type="text" id="txt">
 
1. Create a function in JavaScript called btnClicked which has 0 parameters
1b. Update your HTML to add an onclick to your button, to call this function.
2. When you click the button, it should change the margin of the second input (with id "txt") to 100px
3. Get the value from the txt input, and save it in a variable. (remember the txt input is an object, with a variable 'value' inside of it)
4. Now instead, change the margin using the value you save in your variable.
 
Example:
If the txt has the value 200px, the margin should be 200px when they click the button.
If the txt has the value 50px, the margin should be 50px when they click the button.
Then: Update the code, so that you can just type 50 in the input txt (Instead of 50px)
{"name":"JavaScript Week 4 excercises", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Level 1: Create a variable called title with a value e.g. \"Mr.\", or \"Ms.\" (string) Create a variable called name with a name Use console.log to print the title plus the name (using +), with a space after the title., Level 2:   Create a variable called year with value 2023 (number) Create a variable called ageAtEndOfYear with your age at the end of the year Create a variable called birthYear with value year - ageAtEndOfYear Use console.log to print your birthYear, Level 3:   Create a function called songOfTheDay, it should have 0 parameters The function should use console.log to print a name of a song Call the function","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
Powered by: Quiz Maker