Question

In: Computer Science

/* Assignment: Complete this javascript file according to instructions given in the comments. */ // 1)...

/* Assignment:
Complete this javascript file according to  instructions
given in the comments. */

// 1) Declare a variable named myName equal to your first name
//Firstname is Susan
// Construct a basic IF statement that prints the variable to the
// console IF the length of myName is greater than 1



// 2) Copy your IF statement from above and paste it below
// Change the IF statement to check if the length of myName
// is greater than 10.
// Add an ELSE statement to it that prints your last name
// to the console



// 3) Copy the IF / ELSE statement from #2 and paste it below
// Add an ELSE IF statement to it that checks if the length of
// myName is greater than 3. If true, print the word "javascript"
// to the console.



// 4) Think of your 5 favorite foods.
// 5 fav foods: sushi, spaghetti, tacos, ramen, wings
// Set a variable named myFaveFood equal to a random number from 1 to 5.
// Construct a SWITCH statement that will print one favorite food to
// the console for each number 1 through 5.



// 5) Declare a variable named myNum and set it equal to
// a random number from 1 to 100 (using the Math object).
// Construct a TERNARY statement with the ternary operator
// that checks if the number is greater than or equal to 75.
// If true, print "Great weather!" to the console
// If false, print "Still cold!" to the console

Solutions

Expert Solution

Ans 1.

<!Doctype html>
<html>
<body>
<h2>first part</h2>

<p>First name is : </p>
<p id="part1"></p>
<script> //start of javascript
var myname = "Susan"
var strnglen = myname.length;
if (strnglen > 1) //checking if length of firstname greater than 1
{
document.getElementById("part1").innerHTML = myname; //printing the first name if condition satisfies
}
</script> //end of javascript
</body>
</html>

Ans 2.

<!Doctype html>
<html>
<body>
<h2>first part</h2>

<p>First name is : </p>
<p id="part2"></p>
<script>
var myname = "Susan"
var lastname = "mathhew"
var strnglen = myname.length;
if (strnglen > 10)
{
document.getElementById("part2").innerHTML = myname;
}
else
{
document.getElementById("part2").innerHTML = lastname; //printing the else part if the condition doesn't satisfies
}
</script>
</body>
</html>

Ans 3.

<!Doctype html>
<html>
<body>
<h2>first part</h2>

<p>First name is : </p>
<p id="part3"></p>
<script>
var myname = "Susan"
var lastname = "mathhew"
var strnglen = myname.length;
if (strnglen > 10)
{
document.getElementById("part3").innerHTML = myname;
}
else if(strnglen >3) //use of else if
{
document.getElementById("part3").innerHTML = "javasript";
}
else
{
document.getElementById("part3").innerHTML = lastname;
}
</script>
</body>
</html>

Ans 4.

<!Doctype html>
<html>
<body>
<h2>first part</h2>

<p>First name is : </p>
<p id="part4"></p>
<script>
var myFaveFood = Math.floor(Math.random() *5) + 1; //function to generate random number
var favfood; //variable to store the favorite food name
switch(myFaveFood)
{
case 1 : favfood = "sushi";
   break;
     
case 2 : favfood = "spaghetti";
   break;

case 3 : favfood = "tacos";
   break;

   case 4 : favfood = "ramen";
   break;      
     
case 5 : favfood = "wings";
   break;
}
document.getElementById("part4").innerHTML = favfood;
</script>
</body>
</html>

Ans 5.

<!Doctype html>
<html>
<body>
<h2>first part</h2>

<p>First name is : </p>
<p id="part5"></p>
<script>
var myNum = Math.floor(Math.random() *100) + 1;
var weather;
weather = (myNum >= 75) ? "Great Weather!" : "Still Cold!"; //use of ternary operator
document.getElementById("part5").innerHTML = weather;
</script>
</body>
</html>


Related Solutions

/* Assignment : Complete this javascript file according to the individual instructions given in the comments....
/* Assignment : Complete this javascript file according to the individual instructions given in the comments. */ // 1) Utilize comments to prevent the following line from executing alert('Danger!'); // 2) Assign a value of 5 to a variable named x // and print the value of x to the console // 3) Assign a value of 10 to a variable named myNum // and print the value of myNum to the console // 4) Assign the product of x...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
**CODED IN C LANGUAGE** Case 1: The given snapshot in the assignment instructions checks for the...
**CODED IN C LANGUAGE** Case 1: The given snapshot in the assignment instructions checks for the following: P to be switched with Q (Once done will remain as it is in all the rows) If the user enters the same P again, the program must not make any changes For instance, given elements are 0123456789 3 4          0              0124456789 2 5          1              0154456789 (Keeping the change in Row 0 (input for row 1); 2 is switched to 5) 1 6          2              0654456789 (Keeping...
Instructions: Complete the following case study and upload it to the assignment section prior to the...
Instructions: Complete the following case study and upload it to the assignment section prior to the due date. This will contribute towards the case study portion of a student’s grade. Case study answers must be typed. Point values are assigned per question. Patient Profile M.W. is a 65-year-old female. She is a retired auto worker who lives in a condo with her golden retriever, Charlie. She has a history of diabetes type II diagnosed 3 years ago. She had a...
Respond to the following prompt to complete the CTE assignment. Be sure to follow the instructions...
Respond to the following prompt to complete the CTE assignment. Be sure to follow the instructions in the syllabus and your grade will be determined through the use of the related rubric (also located in the syllabus). As the Baby Boom generation continues to retire from the labor force, the ratio of retirees to workers will continue to increase. How will this demographic change impact the Social Security program? What "solution" or "solutions" would best offset the harmful effects of...
(Javascript) Modify the JavaScript file to implement a function named calculateTotalPrice. At the bottom of the...
(Javascript) Modify the JavaScript file to implement a function named calculateTotalPrice. At the bottom of the file are sample inputs and outputs to test your implementation. /* * The price per ticket depends on the number of tickets * purchased, there are 4 ticket pricing tiers. Given the * number of tickets return the total price, formatted to * exactly two decimal places with a leading dollar sign. * Tier 1: *   Minimum number of tickets: 1 *   Price per...
First create the text file given below. Then complete the main that is given. There are...
First create the text file given below. Then complete the main that is given. There are comments to help you. An output is also given Create this text file: data1.txt -59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 62 -5 95 42 ` Create a project and a Main class and copy the Main class and method given below. First declare the array below the comments that tell you to declare it. Then there...
Memo Assignment #4 Instructions: This will be done in a professional memo format with complete sentences...
Memo Assignment #4 Instructions: This will be done in a professional memo format with complete sentences that explain your process and conclude in a recommendation. I would expect the memo to be no less than one full page and no more than four pages. The goal is two-fold: the professional recommendations AND the appropriate presentation. Heavenly Scents was founded by Riley Williams when she bought Bund Farm in 2015. Heavenly Scents has two departments, a harvesting department and a processing...
Instructions: You must complete the questions below. All will be included in a SINGLE PDF file...
Instructions: You must complete the questions below. All will be included in a SINGLE PDF file and turned into Blackboard or handed at the start of class. The due date is specified on the syllabus. Remember, late work is not accepted. You will need an Executive Summary, PowerPoint (one to page/color) and Excel spreadsheet. Be prepared to present your findings in class. Purpose: You must evaluate the various options to ship freight from Asia to the USA. You MUST find...
Instructions: The assignment is based on the mini case below. The instructions relating to the assignment...
Instructions: The assignment is based on the mini case below. The instructions relating to the assignment are at the end of the case. Katie Holmes and Sam Wilson are facing an important decision. After having discussed different financial scenarios into the wee hours of the morning, the two computer engineers felt it was time to finalize their cash flow projections and move to the next stage – decide which of two possible projects they should undertake. Both had a bachelor...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT