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...
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
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...
Download this file to your hard drive and follow the instructions in the Module 9 Assignment...
Download this file to your hard drive and follow the instructions in the Module 9 Assignment (Word) document. Prepare two files for your post. The first file should be a text file containing your Python solution. The second file should contain your output file(txt). Complete the following using Python on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples:...
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...
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...
(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...
This needs to be written in JavaScript with two files. One HTML file and a JavaScript...
This needs to be written in JavaScript with two files. One HTML file and a JavaScript file. Make an empty HTML file, put three buttons inside the body and an empty main tag below the buttons. The text of the buttons should be "Foo", "Bar", and "FooBar" respectively. Don't put the " in the buttons that's just for clarification in these instructions. Add unique IDs to each button In your JavaScript, get 3 separate references to the buttons using the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT