Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Now that you've coded your solution to the practice problem, I'll show you how I did it. Remember, there are almost always more than one way to solve a problem.
Feedback, please!
We're looking for feedback on this new type of practice workshop. When you're finished, could you please review the workshop by filling out this short form? We appreciate it!
How did it go?
0:00
Were you able to complete the challenge?
0:01
If not, no worries, you can watch my
solution compared to what you wrote and
0:04
then try the challenge again.
0:09
Let's review.
0:11
Step one, create a variable named hours
and set it to the integer value of 40.
0:12
Variables start with the $ sign.
0:18
So $hours = 40.
0:21
Because this is an integer,
we do not need to use quotation marks.
0:25
Step two,
create a variable named productivity and
0:30
set it to the float value of 10.5.
0:34
$productivity = 10.5.
0:37
Again, with number values,
we do not need to use quotation marks.
0:41
Step three, create a third
variable named firstTotal and
0:47
set it equal to the value of
multiplying hours by productivity.
0:51
$firstTotal = $hours * $productivity.
0:56
Step four, add 1 to the hours variable.
1:02
There are many different ways to do this,
but
1:06
I'm going to use the shortcut
that just adds 1.
1:08
$hours++.
1:12
Step five, subtract 0.5 from
the productivity variable.
1:14
Again, there are multiple ways to do this.
1:20
I've chosen to use $productivity -= .5.
1:22
This takes the original productivity
value and subtracts 0.5.
1:27
Step 6, create a third variable,
named secondTotal, and
1:33
set it equal to the new value of
multiplying hours by productivity.
1:38
This should look just like
we did in step three.
1:43
Finally, for step seven, replace
the comments to add firstTotal, and
1:47
secondTotal to the following output.
1:52
We need to echo and then the variable
name, closing each line with a semicolon.
1:55
Let's run our solution.
2:03
View > Show Console.
2:07
php index.php.
2:09
If your solution was different than mine,
that's great.
2:13
Seldom is there only one solution.
2:17
If you see something
interesting in my code,
2:20
you should try to implement
it in your own program.
2:23
Keep practicing, so
you can master these new skills.
2:26
Until next time, happy coding.
2:29
You need to sign up for Treehouse in order to download course files.
Sign up