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...
/* Assignment : Complete this javascript file according instructions in comments. */ // 1) Create a...
/* Assignment : Complete this javascript file according instructions in comments. */ // 1) Create a for loop that loops through its code block 10 times // In the first statement, set the variable i equal to zero // In the second statement, tell the loop to execute while i is less than ten // In the third statement, increment i by one each time the loop executes // In the code block of the loop, print the variable i...
/* Complete this javascript file according to the individual instructions given in the comments. */ //...
/* Complete this javascript file according to the individual instructions given in the comments. */ // 1) Declare an array named myArray // Assign myArray three elements: 'Tuesday',3,true // Print myArray to the console with console.log() // 2) Use typeof on each element in myArray // Example: typeof myArray[0]; // Print all 3 lines to the console with console.log() // 3) Declare a variable named myStart and set it to // the value of the length property applied of myArray...
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue //...
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue // Assign myValue the value of "Hello, how's it going?" // Print the value of myValue to the console // 2) Use the charAt() method to display the letter t // from the variable myValue in the console // 3) Use the indexOf() method to display the position of "going" // from the variable myValue in the console // 4) Use the slice() method to...
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop...
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop 10 questions that you would ask a management official responsible for the financial planning for the organization you have chosen to research for the week 3 paper. 2. Make sure the questions will give you insight into what the company looks for when preparing their yearly budget, fiscal planning strategies, as well as how they monitor their financial condition throughout the year and make...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT