大家好,提前感谢您的帮助。
所以我想找到二维数组中最大的数字。下面是代码:
const matrix = [
[2, 56, 10],
[20, 34, 10],
[23, 144, 26]
];
let maximum = matrix[0][0];
for (var row = 0; row < matrix.length; row++) {
for (var col = 0; col < matrix.length; col++) {
if (matrix[row][col] > maximum) {
maximum = matrix[row][col];
};
};
};
document.write(' -- ', maximum);
Run Code Online (Sandbox Code Playgroud)
这是我的问题- 您能否帮助我理解为什么当我在数组中有更多数字时我看不到最大数字 - 请在下面找到一个示例):
const matrix = [
[2, 56, 10, 14, 422, 3242],
[20, 34, 55, 100, 33, 422],
[23, 12, 14, 26, …
Run Code Online (Sandbox Code Playgroud)我已经圈了几个小时,我一直在使用这段代码得到错误:
$('div.colA div.region-sidebar-left div.menu-block-wrapper').find('li').each(function() {
if ($(this).find('> ul').size() > 0) {
$(this).addClass('has_child');
}
});
Run Code Online (Sandbox Code Playgroud)
它应该做的就是找到<li>
一个孩子<ul>
并给它上课.简单.
我正在尝试创建一个计算器,它给出了一个人收入的百分比.我是JavaScript和jQuery的新手.
这给了
未捕获的ReferenceError:未定义计算未
捕获的语法错误:意外的标记
function calculate();
{
var annual_Income = jQuery('#a1').val();
var income_Pledged = (jQuery('#a2').val()/100;
var x = annual_Income * income_Pledged;
var weekly = Math.floor(x/52);
var monthly = Math.floor(x/12);
var quarterly = Math.floor(x/4);
var annual_total = weekly + monthly + quarterly;
var htmlstr = '<div> <p>Annual Household Income: $ ' + annual_Income + '</p><p>Weekly Pledge: $ ' + weekly + '</p><p>Monthly Pledge: $ ' + monthly +
'</p><p>Quaterly Pledge: $ ' + quarterly + ' </p><p>Annual Pledge: $ ' + …
Run Code Online (Sandbox Code Playgroud) 正在构建加密程序.我计划将字符混合在一起(例如:1234567890将加密为6345809127).
不幸的是,为了混合特定的模式,我需要一个字符串为十的倍数,所以我的计划是添加一个字符,'
直到字符串的长度为十的倍数.例如,如果我输入hello(5个字符),脚本将插入,'
直到它是10个字符,所以它看起来像hello'''''
.
关于如何做到这一点的任何想法?
在我的应用程序中,我正在访问远程URL并获得如下所示的JSON响应。JSON响应具有名为的属性created_at
。
在JavaScript中,我需要获取当前日期减日期(-),created_at
然后计算创建注释的天数。
我怎样才能做到这一点?
{
"id":12578834,
"title":"Joint R&D Has Its Ups and Downs",
"url":"http://semiengineering.com/joint-rd-has-its-ups-and-downs/",
"num_points":1,
"num_comments":0,
"author":"Lind5",
"created_at":"9/26/2016 2:28"
}
Run Code Online (Sandbox Code Playgroud) 我希望代码片段能够以i的值打印出100次.
但它只打印出一次,如下所示.
我在这里错过了什么?
let i = 0;
for (; i++; i < 100) {
console.log('Loop ==>' + i);
}
console.log('Loop Done');
console.log('Value of i ==>' + i);
Run Code Online (Sandbox Code Playgroud)
我想获取json响应的值。我写了一个如下的Ajax函数:
$.ajax({
url: '/v1/shopify-Ajax/ajax.php',
method: 'post',
data: {datalog: dataLog, variant: $('#prod').val()}
})
.success(function(response){
//window.location.href = "/v1/thank-you.php";
})
Run Code Online (Sandbox Code Playgroud)
我从服务器端脚本得到如下响应:
{"order":
{"id":303657910281,
"email":"test20@code1.com",
"closed_at":null,
"created_at":"2018-03-19T01:04:58-07:00",
"updated_at":"2018-03-19T01:04:58-07:00",
"number":811,
"note":null,
"token":"9709d7c295ac1dbbaf29c2d09a9d5a9d",
"gateway":"",
"test":false,
"total_price":"82.49",
"subtotal_price":"82.49",
"total_weight":null,
"total_tax":"0.00",
"taxes_included":false,
"currency":"USD",
"financial_status":"paid",
"confirmed":true,
"total_discounts":"0.00",
"total_line_items_price":"82.49","cart_token":null,"buyer_accepts_marketing":false,"name":"#1811","referring_site":null,"landing_site":null,"cancelled_at":null,"cancel_reason":null,"total_price_usd":"82.49","checkout_token":null,"reference":null,"user_id":null,"location_id":null,"source_identifier":null,"source_url":null,"processed_at":"2018-03-19T01:04:58-07:00","device_id":null,"phone":null,"customer_locale":null,"app_id":2306584,"browser_ip":null,"landing_site_ref":null,"order_number":1811,"discount_codes":[],"note_attributes":[],"payment_gateway_names":[""],"processing_method":"","checkout_id":null,"source_name":"2306584","fulfillment_status":null,"tax_lines":[],"tags":"","contact_email":"test20@code1.com","order_status_url":"https:\/\/checkout.shopify.com\/19258983\/orders\/9709d7c295ac1dbbaf29c2d09a9d5a9d\/authenticate?key=0XXX","line_items":[{"id":610330640393,"variant_id":2323256639497,"title":"XX","quantity":1,"price":"82.49","sku":"","variant_title":"3 XX","vendor":"X1","fulfillment_service":"manual","product_id":235965415433,"requires_shipping":false,"taxable":false,"gift_card":false,"pre_tax_price":"82.49","name":"XXXX","variant_inventory_management":null,"properties":[],"product_exists":true,"fulfillable_quantity":1,"grams":0,"total_discount":"0.00","fulfillment_status":null,"tax_lines":[]}],"shipping_lines":[],"billing_address":{"first_name":"","address1":"","phone":null,"city":"","zip":"","province":"","country":null,"last_name":"","address2":null,"company":null,"latitude":null,"longitude":null,"name":"","country_code":null,"province_code":null},"shipping_address":{"first_name":"test","address1":"6116 Beverly Dr","phone":null,"city":"Adair","zip":"50002","province":"Iowa","country":"United States","last_name":"tes","address2":null,"company":null,"latitude":null,"longitude":null,"name":"test tes","country_code":"US","province_code":"IA"},"fulfillments":[],"refunds":[],"customer":{"id":324158947337,"email":"test20@code1.com","accepts_marketing":false,"created_at":"2018-03-19T01:04:58-07:00","updated_at":"2018-03-19T01:04:58-07:00","first_name":"test","last_name":"tes","orders_count":1,"state":"disabled","total_spent":"0.00","last_order_id":303657910281,"note":null,"verified_email":true,"multipass_identifier":null,"tax_exempt":false,"phone":null,"tags":"","last_order_name":"#1811","default_address":{"id":371809157129,"customer_id":324158947337,"first_name":"test","last_name":"tes","company":null,"address1":"6116 Beverly Dr","address2":null,"city":"Adair","province":"Iowa","country":"United States","zip":"50002","phone":null,"name":"test tes","province_code":"IA","country_code":"US","country_name":"United States","default":true}}}}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何直接访问订单ID(无循环)并检查订单ID是否为null或空白。
!
这是我的回复数据:
var data = [{
'name': 'ragu',
'taxprice': '20'
} {
'name': 'ram',
'taxprice': '20'
} {
'name': 'sandy',
'taxprice': '20'
} {
'name': 'ramu',
'taxprice': '20'
}];
Run Code Online (Sandbox Code Playgroud)
我想添加所有的taxprice值
我的预期结果是小计= 80
我正在制作一个包含范围输入滑块的网站。我希望滑块根据滑块的值更改颜色。
例如,如果该值为0,则拇指颜色为rgb(255, 0, 0);
,如果为100,则颜色为rgb(0, 255, 0);
,拇指将改变颜色。
需要明确的是,我不需要这样的东西:
if slider_value <= 29:
thumb_color = rgb(255, 0, 0)
else if slider_value >= 30 && slider_value <= 69:
thumb_color = rgb(255, 255, 0)
else
thumb_color = rgb(0, 255, 0)
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的代码:
if slider_value <= 29:
thumb_color = rgb(255, 0, 0)
else if slider_value >= 30 && slider_value <= 69:
thumb_color = rgb(255, 255, 0)
else
thumb_color = rgb(0, 255, 0)
Run Code Online (Sandbox Code Playgroud)
.slider {
width: 60%;
margin: 50px auto;
-webkit-appearance: none;
height: …
Run Code Online (Sandbox Code Playgroud)我正在尝试传递要连接到 URL 地址的字符串值数组,以创建内联图像块。我有以下几点:
<div className="row text-center">
{ this.state.sketchs.map((sketch, key) => {
return(
<div key={key} className="col-md-3 mb-3">
<div className="token" img src={{ 'https://ipfs.infura.io/ipfs/' : sketch }}></div>
<div>{sketch}</div>
</div>
)
})}
</div>
Run Code Online (Sandbox Code Playgroud)
css文件有以下内容:
.token {
height: 150px;
width: 150px;
border-radius: 50%;
display: inline-block;
}
Run Code Online (Sandbox Code Playgroud)
我成功地将数组“草图”推送到下面以蓝色突出显示的“令牌”中。
但我希望将突出显示的蓝色“散列”用作 img 源,并在每个源的开头加上“https://ipfs.infura.io/ipfs/”。
我将如何实现这一目标?为什么我的代码在上面不起作用?任何帮助,将不胜感激!