找到每个子数组中的最大数字,然后创建这些最大数字的数组.[[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]
我写了一些代码,我无法弄清楚它有什么问题.也许Array.push()方法不起作用或者也许for循环.
function largestOfFour(arr) {
var main = [];
for(k=0;k<arr.length;k++){
var long= 0;
for(i=0;i<arr[k].length;i++){
if(arr[k][i]<long) {
arr[k][i] = long;
}
main.push[long];
}
}
return main
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]], "");
Run Code Online (Sandbox Code Playgroud) 我试图使代码片段工作.我刚刚开始这个,我目前只为我的手机设计它.您可以通过单击项目和今天来查看问题.
我有一个div(#data-container),它由两个div(.project, .today)组成,我希望这两个div并排像tab一样.所以,当我点击它们各自的按钮时,它会滑动并显示相应的div.我有它工作,但有2个问题.
它们如何工作 - #data-container有white-space: nowrap(子div不会包裹并且并排放置,滑动会起作用)并且它的子div(.project and .today)设置为width: 100%和inline-block.
这个问题
将data-container需要能够垂直滚动,并能包裹当前选定的div周围的文本,但white-space: nowrap使文本溢出.我试过word-wrap: break-word,它不起作用.我也可以通过设置它来使它工作display: hidden但我希望div滑动.
我不明白为什么会出现这个问题.当我设置#data-container为overflow-y: scroll,它使div水平滚动,这打破了整个系统.
我需要一种方法来使data-container唯一的垂直滚动和包装文本.
玉
extends ./layout.jade
block content
#maindiv
.sidebar
#profile
img(src= ' #{image} ', width=40, height=40)
span #{name}
ul
li Home
li +Project
li +Task
li Reminders
li Statistics
li Settings
li Help
li
a(href='/logout') Log Out …Run Code Online (Sandbox Code Playgroud) 我刚学会了switch语句.我正在通过构建一些东西来练习它.当我将变量的值设置为一个数字时,它可以工作但是当我向用户询问一个数字时,它总是输出默认语句.
它适用于以下代码:
confirm("You want to learn basic counting?");
var i = 0;
switch (i) {
case 0:
console.log(i);
i++
case 1:
console.log(i);
i++;
case 2:
console.log(i);
i++;
case 3:
console.log(i);
i++;
case 4:
console.log(i);
i++;
case 5:
console.log(i);
i++;
case 6:
console.log(i);
i++;
case 7:
console.log(i);
i++;
case 8:
console.log(i);
i++;
case 9:
console.log(i);
i++;
case 10:
console.log(i);
console.log("Congratulations!");
break;
default:
console.log("Buzz, wronghh");
break;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我向用户询问价值时,它不起作用.以下代码不起作用:
confirm("You want to learn basic counting?");
var i = prompt("Type any number …Run Code Online (Sandbox Code Playgroud) 为什么这个while循环在末尾打印"1"?我只想打印console.log语句.在使用Codecademy时看到了.
for (i = 0; i < 2; i++) {
console.log("I understand for loops twice..lol");
};
var whileUnderstand = 0;
while(whileUnderstand < 2) {
console.log("I understand while loops twice..lol");
whileUnderstand++;
}
Run Code Online (Sandbox Code Playgroud)
这个问题没有直接回答我提出的问题.此外,它只包含console.log语句而不是循环.主要是,没有答案说"控制台只是输出语句的最后评估值." 这是解决我的问题的答案.