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 javascript file according to the individual instructions given in the comments. */ // 1)...
/* complete javascript file according to the individual instructions given in the comments. */ // 1) Prompt the user to enter their first name. // Display an alert with a personal greeting for the user // with their first name (example: Hello, Dave!) // 2) Create a Try code block that will cause a ReferenceError. // Create a Catch code block that will display the error in the // console with console.error() // 3) Prompt the user to enter a...
/* Complete this javascript file according to the individual instructions given in the comments. */ //1)...
/* Complete this javascript file according to the individual instructions given in the comments. */ //1) Create an Object using an Object Literal (the easiest way) // Name your object Breakfast // Your object should have 3 key:value pairs // The three keys should be: breakfast, lunch, dinner // Put your food choice for each as the value // 2) Display the keys of your Breakfast object in the // console. We have learned two ways to do this.. either...
/* 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...
Complete this javascript question according to the instructions given in the comments. *** DO NOT CHANGE...
Complete this javascript question according to the instructions given in the comments. *** DO NOT CHANGE any of the code that you are not instructed to. */ //////////////////// // Hint: If you see a console.log() in my examples, it is // likely a "return" goes there in your assignment. /////////////////// // 1) Define a "Vehicle" class that has a "wheels" property equal to 4 in // the constructor and a method named "rolling" that returns a string // equal to...
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...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include <vector> #include <iostream> #include <fstream> using namespace std; vector<float>GetTheVector(); void main() { vector<int> V; V = GetTheVector(); //reads some lost numbers from the file “data.txt" and places it in //the Vector V Vector<int>W = getAverageOfEveryTwo(V); int printTheNumberOfValues(W) //This should print the number of divisible values by 7 //but not divisible by 3. PrintIntoFile(W); //This prints the values of vector W into an output file...
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: //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT