Question

In: Computer Science

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 display "how's it going?"
// from the variable myValue in the console


// 5) Declare a variable named myOtherValue
// Assign myOtherValue the value of "Ok?"
// Use the concat() method on the variable myValue
// to concatenate myValue and myOtherValue
// Specify a new line as the first parameter of concat()
// Print the result to the console


// 6) Declare a variable named myRandom
// Assign myRandom a non-rounded value between 0 and 1 using Math.random()
// Print the result to the console


// 7) Now assign a random value between 1 and 10 to myRandom
// Use Math.floor() and Math.random() to accomplish this
// Print the result to the console


// 8) Print the length of the variable myValue to the console


// 9) Set the contents of the variable myValue to all lowercase
// Find the method to do this on your own
// Print the variable to the console to show it now holds all lowercase


// 10) **Solving a problem!
// Declare a variable named myName and assign it your first name
// Utilize the length property, Math.floor(), Math.random() and charAt()
// methods to write a line of code that will randomly display a character
// from your firstname in the console... refer to the examples of each
// method at w3schools.com and MDN Web Docs

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new web page with name "Assignment03.html" is created, which contains following code.

Assignment03.html :

<!DOCTYPE html>

<html lang="en">

<head>

<!-- title for web page -->

<title>Assignment 03</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

<!-- <Script> is used for javascript -->

<script>

/* 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

var myValue="Hello, how's it going?";

console.log("1.myValue : "+myValue);

// 2) Use the charAt() method to display the letter t

// from the variable myValue in the console

console.log("charAt: "+myValue.charAt(14));

// 3) Use the indexOf() method to display the position of "going"

// from the variable myValue in the console

console.log("indexOf: "+myValue.indexOf("going"));

// 4) Use the slice() method to display "how's it going?"

// from the variable myValue in the console

console.log("slice : "+myValue.slice(7,22));

// 5) Declare a variable named myOtherValue

// Assign myOtherValue the value of "Ok?"

// Use the concat() method on the variable myValue

// to concatenate myValue and myOtherValue

// Specify a new line as the first parameter of concat()

// Print the result to the console

var myOtherValue="Ok?";

console.log("concat() :"+myValue.concat("\n",myOtherValue));

// 6) Declare a variable named myRandom

// Assign myRandom a non-rounded value between 0 and 1 using Math.random()

// Print the result to the console

var myRandom=Math.random();

console.log("myRandom (0-1) : "+myRandom);

// 7) Now assign a random value between 1 and 10 to myRandom

// Use Math.floor() and Math.random() to accomplish this

// Print the result to the console

myRandom=Math.floor(Math.random() * 11);

console.log("myRandom (0-10) : "+myRandom);

// 8) Print the length of the variable myValue to the console

console.log("length : "+myValue.length);

// 9) Set the contents of the variable myValue to all lowercase

// Find the method to do this on your own

// Print the variable to the console to show it now holds all lowercase

console.log("Lower Case : "+myValue.toLowerCase());

// 10) **Solving a problem!

// Declare a variable named myName and assign it your first name

// Utilize the length property, Math.floor(), Math.random() and charAt()

// methods to write a line of code that will randomly display a character

// from your firstname in the console... refer to the examples of each

// method at w3schools.com and MDN Web Docs

var myName="Virat";

console.log(myName.charAt(Math.floor(Math.random()*myName.length)));

</script>

</body>

</html>

======================================================

Output : Open web page Assignment03.html in the browser and will get the screen as shown below

Screen 1 :Assignment03.html

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

/* 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...
Questions: 1) // declare integer variable sum equal to zero // declare variable integer i //...
Questions: 1) // declare integer variable sum equal to zero // declare variable integer i // declare while loop condition where i is less then 25 // inside of brackets calculate the sum of i (addition) // increment i // outside the loop print the sum of values ============================================= 2) Create a sentinel value example if I press number 0 it will display the sum of data // create a scanner // prompt the user to to enter the numbers...
Python HW with Jupyter Notebook Declare a variable named DATA as a dictionary object. Assign the...
Python HW with Jupyter Notebook Declare a variable named DATA as a dictionary object. Assign the set of key/value pairs shown below. Create a function named iter_dict_funky_sum() that takes one dictionary argument.    Declare a running total integer variable. Extract the key/value pairs from DATA simultaneously in a loop. Do this with just one for loop and no additional forms of looping. Assign and append the product of the value minus the key to the running total variable. Return the funky...
/* 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...
(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...
1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student...
1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student (as whole number) b. a variable to store a letter grade for a course, like A, B, or C c. a variable to store an average for a student (may have decimal places) d. a variable to represent if a student passed the course or not, with a value of TRUE or FALSE e. a constant to represent the passing grade of 65 2....
In C++ ============================================================EXERCISE 2 PROBLEM SET============================================================ 1) Declare a structure named TempScale , with the following...
In C++ ============================================================EXERCISE 2 PROBLEM SET============================================================ 1) Declare a structure named TempScale , with the following members:fahrenheit: a doublecentigrade: a doubleNext, declare a structure named Reading , with the following members:windSpeed: an inthumidity: a doubletemperature: a TempScale str ucture variableNext define a Reading structure variable. ------------------------------------------------------------ 2) Write statements that will store the following data inthe variable you defined in Problem 1:Wind Speed: 37 mphHumidity: 32%Fahrenheit temperature: 32 degreesCentigrade temperature: 0 degrees ------------------------------------------------------------ 3) Write a function called showReading. It...
What does it mean to declare a variable? Give an example.
C++ programming homeworkWhat does it mean to declare a variable? Give an example.What does it mean to assign a value to a variable? Give an example.What is the different between assigning and initializing? Give examples.
Which of the following statements is NOT correct? A. It is allowed to declare a variable...
Which of the following statements is NOT correct? A. It is allowed to declare a variable and initialize it in one statement. B. Once a variable is declared and initialized, you can change its value later on. C. The variable declaration tells the compiler to allocate appropriate memory space for the variable based on its data type. D. It is allowed to declare two variables with the same name but with different data type.
How does one declare a class variable in C#?
How does one declare a class variable in C#?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT