JavaScript代写:CPSC1045EvaluateComplexExpressions


练习JS基础语法,一步一步实现各种表达式。

Overview

In this lab we will manually evaluate complex expressions in order to better
understand how JavaScript interprets these expressions step-by-step. You are
required to show your work (i.e., show each step of how you evaluate/find the
solution for each expression). The web console in the browser can help you
check your answer, but it should not do the work for you.

Resources

Lab work

Step 1

Open a new text file and evaluate each of the following 10 expressions. Make
sure to show ALL OF THE STEPS you took to solve the expression. Answers that
do not show enough steps will receive a grade of 0. The first one has been
done for you.
“Dog” + 2 > 3 && true
Steps:
“Dog2” > 3 && true false && true
false
Final Solution: false
true || false && true
var firstName = “trouble”;
var lastName = “double”;
(firstName === “Batman” || firstName === “Trouble” ) && (lastName === “Batman” || lastName === “kong” )
var a = 21;
a += 3;
var b = 5;
b -= a;
(a < 1) || (b >= 1) && (a != b)
var pet = “alligator”;
var escape = “boat”;
“The “ + pet + “ escaped. It was last seen on a “ + escape;
var George = “orge”;
var nickname = “Conquerer”;
var combinedName = George + “ “ + nickname;
(combinedName === George) || (George !== “George”) &&(combinedName === “Conquerer”) || (nickname === 42)
((42 === “42”) && (42== “42”)) || ((42 < “Whistle”) || (42 > “234”))
((24*23+12/2+22) % 2 === 1)
((Math.pow(3,3) === 27) || (Math.cos(Math.PI) === 0)) || (Math.pow(Math.sin(1.2),1)+Math.pow(Math.cos(1.2),2) === 1)
var sentence = “The world is green!”; sentence.substring(4,9) === “world” && sentence.length < 20 && sentence.length > 5 && sentence.substring(0,3) === “The world is red”.substring(0,3);
var bigCar = true;
var bearTrap;
“The variable bigCar has the value : “+ bigCar + “, while variable bearTrap is “ + bearTrap + “If I compare bearTrap with undefined I get “ + bearTrap===undefined
—|—

Step 2

Now we are going to write our very first runnable JavaScript. Download a1.zip
from D2L and extract the a1.html file. Inside the <script> tags add the
necessary JavaScript to create a word problem that includes a question and
answer.

  • A sample word problem may look like:
  • Q: Jamie makes 5 cupcakes and eats 3 of them. How many cupcakes are left?
  • A: 2
  • The next time the page loads, the numbers should change, so the problem may look like:
  • Q: Jamie makes 12 cupcakes and eats 7 of them. How many cupcakes are left?
  • A: 5
  • The numbers used in this word problem should change randomly. This means that we need to generate the numbers for the questions and the answer using JavaScript
    Note: you will need to use the Math.random() function and the innerHTML
    property like we did in Lab Exercise 1 to complete this exercise.

文章作者: SafePoker
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SafePoker !
  目录