寻找JavaScript编码测验的答案

时间:2017-09-12 18:21:33

标签: javascript

/*
 * Programming Quiz: One Awesome Message (2-12)
 *
 * 1. Create the variables
 *     - firstName
 *     - interest
 *     - hobby
 * 2. Create a variable named awesomeMessage and, using string concatenation and the variables above, create an awesome message.
 * 3. Print the awesomeMessage variable to the console
 */

    // Add your code here

我无法将awesomeMessage变量打印到控制台,如下所示:

  

“嗨,我的名字是朱莉娅。我爱猫。在业余时间,我喜欢玩电子游戏。”
  “嗨,我的名字是詹姆斯。我喜欢棒球。在业余时间,我喜欢读书。”

我是新来的......请不要评价我。这是我写的代码(并坚持下去):

 firstName = ["Julia", "James"];
 interest = ["cats", "baseball"];
 hobby = ["play video games", "read"];
var awesomeMessage = "Hi, my name is " + firstName +". " + "I love "+interest+ ". "+ "I like to "+hobby+ ".";
console.log(awesomeMessage);

5 个答案:

答案 0 :(得分:0)

我已经更新了我使用字符串而不是数组的答案。看看它与我以前的比较。

//declaring the variable using var keyword defines the scope
var firstName = "Julia";
var interest = "cats";
var hobby = "play video games";

//concatenate all our vars together into longer string
var awesomeMessage = "Hi, my name is " + firstName + ". " + "I love " + interest + ". " + "I like to " + hobby + ".\n";

//see the result of your string concatenation
console.log(awesomeMessage);

答案 1 :(得分:0)

我也参加了这个纳米学位课程并且也被困在这里。我不确定你是否弄清楚了,但你必须从自己的答案中创建自己的例子。构建自己的变量并从中创建一个字符串。

/*
 * Programming Quiz: One Awesome Message (2-12)
 *
 * 1. Create the variables
 *     - firstName
 *     - interest
 *     - hobby
 * 2. Create a variable named awesomeMessage and, using string concatenation and the variables above, create an awesome message.
 * 3. Print the awesomeMessage variable to the console
 */

// Add your code here

var firstName = "fname";
var interest = "programming";
var hobby = "reading";
var awesomeMessage = "Hi, my name is "+firstName+". I love "+interest+". In my spare time, I like to "+hobby+".";

console.log(awesomeMessage);

答案 2 :(得分:0)

var firstName = ["Julia", "James"]
var interest = ["cats", "baseball"]
var hobby = ["play video games", "read"]

var awesomeMessage = "Hi, my name is " + firstName [0] + ". " + "I love " + interest[0] + ". " + "In my spare time, I like to " + hobby[0] + ".\n" 
+ "Hi, my name is " + firstName[1] + ". " + "I love " + interest[1] + ". " + "In my spare time, I like to " + hobby[1] + "." ;

console.log (awesomeMessage)

答案 3 :(得分:0)

试试这个,挑战要求你具体到句点(。):

var awesomeMessage = "Hi, my name is " + firstName + ". " + "I love " + interest + ". " + "In my spare time, I like to " + hobby + ".";

的console.log(awesomeMessage);

答案 4 :(得分:0)

var firstName = ['Julia','James'];
var interest = ['cats','baseball'];
var hobby = ['play video games','read'];
var awesomeMessage = '\"Hi, my name is '+ firstName[0] + '. I love ' + 
interest[0] + '. In my spare time, I like to' + hobby[0] +'.\"\n\"Hi, my name 
is ' + firstName[1] + '. I love ' + interest[1] + '. In my spare time, I like 
to ' + hobby[1] + '.\"';
console.log(awesomeMessage);