2.1 KiB

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
bd7123c9c448eddfaeb5bdef Find the Length of a String 1 找到字符串的长度

Description

您可以通过在字符串变量或字符串文字后面写.length来查找String值的长度。 "Alan Peter".length; // 10例如,如果我们创建了一个变量var firstName = "Charles" ,我们可以通过使用firstName.length属性找出字符串"Charles"长度。

Instructions

使用.length属性计算lastName变量中的字符数,并将其分配给lastNameLength

Tests

tests:
  - text: <code>lastNameLength</code>应该等于8。
    testString: 'assert((function(){if(typeof lastNameLength !== "undefined" && typeof lastNameLength === "number" && lastNameLength === 8){return true;}else{return false;}})(), "<code>lastNameLength</code> should be equal to eight.");'
  - text: 您应该使用<code>.length</code>来获取<code>lastName</code>的长度,如下所示: <code>lastName.length</code> 。
    testString: 'assert((function(){if(code.match(/\.length/gi) && code.match(/\.length/gi).length >= 2 && code.match(/var lastNameLength \= 0;/gi) && code.match(/var lastNameLength \= 0;/gi).length >= 1){return true;}else{return false;}})(), "You should be getting the length of <code>lastName</code> by using <code>.length</code> like this: <code>lastName.length</code>.");'

Challenge Seed

// Example
var firstNameLength = 0;
var firstName = "Ada";

firstNameLength = firstName.length;

// Setup
var lastNameLength = 0;
var lastName = "Lovelace";

// Only change code below this line.

lastNameLength = lastName;

After Test

console.info('after the test');

Solution

// solution required