- Understand and use JavaScript primitive data types (booleans, numbers, strings).
- Apply conditional statements to guide the dragon's learning decisions.
- Utilize loops for practicing coding exercises in JavaScript.
Welcome to the Coding Dragon's lab! In this adventure, you will help the dragon as it embarks on a quest to master JavaScript. You’ll work with booleans to track its study habits, use random numbers to determine how many topics it has studied, and calculate the total hours needed for study.
You'll complete the following iterations, each focusing on specific programming skills.
-
Create a boolean variable
isStudyingJS
and set it totrue
if the dragon is actively studying JavaScript.- Print:
"The dragon is currently studying JavaScript!"
ifisStudyingJS
is true, or"The dragon is taking a break from studying JavaScript."
if false.
- Print:
-
Create a variable
jsTopicsCovered
and set it to a random number between 1 and 10 to represent how many JavaScript topics the dragon has learned.- Print:
"The dragon has covered XX JavaScript topics."
(Replace XX with the actual number).
- Print:
-
Calculate the total
practiceHours
needed, based on the number of topics covered (each topic takes 2 hours to study) and store it in a variable.- Print:
"The dragon needs YY hours to study JavaScript."
(Replace YY withjsTopicsCovered * 2
).
- Print:
- Use conditionals to evaluate the dragon’s learning:
- If
isStudyingJS
istrue
andpracticeHours >= 4
, print:"Excellent job! Keep coding!"
- If
isStudyingJS
isfalse
, print:"The dragon should get back to studying JavaScript!"
- If
jsTopicsCovered < 5
, print:"The dragon needs to cover more topics to master JavaScript."
- If
- Simulate the dragon's practice exercises using a loop:
- Create a variable
exercisesCompleted
initialized to 0. - Use a
while
loop to incrementexercisesCompleted
by 1 until the dragon completes 10 exercises. - Print:
"The dragon has completed ZZ JavaScript exercises."
(where ZZ is the value ofexercisesCompleted
after each increment). - Once the total exercises have been completed, print:
"The dragon's practice session is over! Well done!"
- Create a variable
Bonus 1:
- Create a variable
numberOfDebuggedErrors
and set it to a random number between 1 and 5 (representing how many errors the dragon has debugged). - Use a
for
loop to simulate debugging each error.- Print:
"Error XX debugged!"
for each debugged error. - If the dragon debugs 3 or more errors, print:
"The dragon is becoming a debugging master!"
.
- Print:
Bonus 2:
- Write a function
checkCompletionStatus
that takes a boolean parameterhasCompletedProject
. - Use conditionals to print:
- If
hasCompletedProject
istrue
, print:"The dragon has successfully completed its JavaScript project!"
- If
hasCompletedProject
isfalse
, print:"The dragon needs to finish its project!"
- If
- Call this function using both
true
andfalse
values to show the dragon's project completion status.
Upon completion, run the following commands in your terminal:
git add .
git commit -m "Completed The Coding Dragon Lab"
git push origin master