If your code isn't working as expected, try opening up Firefox's error console to check for (potentially) helpful error messages. If you get stuck, don't hesitate to ask the instructor or a teaching assistant for help.
Tip: Here are some handy keyboard shortcuts:
Select-All: Command-A (Mac), Control-A (Windows)
Copy: Command-C (Mac), Control-C (Windows)
Paste: Command-V (Mac), Control-V (Windows)
runShortExperimentfunction repeats the short exercises from Mini-Lab 1, and adds several new exercises involving more complicated expressions.
runShortExperimentdo? (This is the only statement that is not commented-out.)
alertstatement. (There will still be a comment to the right of the statement, at the end of the line.) What will the function will do now? Update the comment with what you expect the result to be, then test it.
+operator does when used with numbers, strings, or a combination of both. Again, document your expected results in the comments at the end of line, then test that your expectations were correct.
The final set of statements in this function will allow you to experiment
what happens when addition and multiplication operations are combined in
the same statement. Starting with just the first two statements, think
about what you think the output will be, edit the Expected Results (e.g.,
42, or whatever you think the
output will be), uncomment the statements, and run the experiment.
What about the third statement in the block? Do you expect its behavior to be the same as the first statement or the second statement, or neither? Test it. Then go on and do the same for the final two statements in the function.
In this exercise you will add a simple calculator to your page. Your calculator will prompt the user for two numbers and then display the sum, the product, the difference, and the quotient of those two numbers. A sample session might look like the following:
[prompt] Please enter the first number. [user enters] 3 [prompt] Please enter the second number. [user enters] 4 [Output] 3 + 4 = 7 3 - 4 = -1 3 * 4 = 12 3 / 4 = .75
Note: The values returned by the
promptfunction are strings, not numbers. What is the result if you try to use the
+operator on those values?
Tip: Before you can perform arithmetic on string values they must be converted to numbers using the built-in
parseFloatfunction. For example, if the variable
firstNumcontains the string "3", the following command will convert it to the number 3:firstNum = parseFloat(firstNum);
Tip: There are several possible ways to complete this exercise. One possibility would be to create four variables to store the the sum, the product, the difference, and the quotient. You can then use the "+" operator to build the output string. For example, the first output statement might look something like the following: [Click on the
alertcall above to see an explanation. Click on it again to make the explanation disappear.]
Edit the main COMP 105 web page you created in the first lab and add a link to your new Working with Numbers page. (This should be your second link in what will become a set of links to COMP 105 assignments.)
If you worked in a team, each member of your group should do this, so each of you has a link to the new mini-lab page.
people.kzoo.eduserver (remember that its host name for uploading is
peopleftp.kzoo.edu). Test that the link to the Mini-Lab works on the server by clicking on it from your home page.