24.0k views
0 votes
Write JavaScript function that will serve as a constructor for Rectangle object with two data properties width and length. Add method to the rectangle object that will compute and return the area of the rectangle. 2. Write Javascript function that will take as an input a string and check if that string contains letters a, b, c (disregarding case) in order but not necessarily adjacent. The function should return either true or false and needs to use regular expressions.

User Kamilg
by
7.8k points

1 Answer

1 vote

Final answer:

To create a Rectangle object in JavaScript with a width and length data property, you can use a constructor function. To check if a string contains the letters 'a', 'b', 'c' in order (ignoring case) using regular expressions, you can use the test method.

Step-by-step explanation:

In JavaScript, you can create a constructor function for the Rectangle object with the 'width' and 'length' data properties. Here's an example:



function Rectangle(width, length) {
this.width = width;
this.length = length;
}

Rectangle.prototype.calculateArea = function() {
return this.width * this.length;
};

var rectangle = new Rectangle(5, 10);
console.log(rectangle.calculateArea()); // Output: 50



To check if a string contains the letters 'a', 'b', 'c' in order, ignoring case, you can use regular expressions. Here's an example:



function containsLetters(string) {
var regex = /a.*b.*c/i;
return regex.test(string);
}

console.log(containsLetters('AbC')); // Output: true
console.log(containsLetters('CBa')); // Output: false

User PatientOtter
by
8.1k points