Hướng dẫn can array store multiple values in javascript? - mảng có thể lưu trữ nhiều giá trị trong javascript không?

Tôi là một người gầy mới cho JavaScript. Tôi muốn tạo một mảng để lưu trữ nhiều giá trị X và Y cho một đối tượng [mảng [0]], sau đó sử dụng các giá trị này để so sánh với tọa độ Vẽ vẽ đối tượng X và Y.

Ví dụ, tôi có các giá trị sửa chữa x và y như dưới đây: [x: y] 585: 225 584: 231 579: 254 573: 271 570: 279 570: 280

Tôi sẽ nhận được tọa độ đối tượng vẽ X và Y và so sánh với các giá trị trên. Nếu nhiều hơn 3 nhóm giá trị x và y sai thì hãy hiển thị: câu trả lời sai. Có thể làm điều đó? Cảm ơn bạn! xin vui lòng giúp đỡ...

Đây là mã hóa:


  
    
      #contain {
        width: 500px;
        height: 120px;
        top : 15px;
        margin: 0 auto;
        position: relative;    
        }
   
  
var touchList = [];
var plates = [];
    var currentPlates;
    var currentIndex = 0;
    var canvas;
    var ctx;
    var lastPt=null;
    var letsdraw = false;
    var offX = 440, offY = 25;


function init[] {
    var touchzone = document.getElementById["layer1"];
    touchzone.addEventListener["touchmove", draw, false];
    touchzone.addEventListener["touchend", end, false];
    ctx = touchzone.getContext["2d"];
  }

  function draw[e] {
    e.preventDefault[];
var selectedCoordinate = new Object[];
selectedCoordinate.x = e.touches[0].pageX;
selectedCoordinate.y = e.touches[0].pageY;
touchList.push[selectedCoordinate];
console.log["X: " + e.touches[0].pageX + " Y: " + e.touches[0].pageY];

    if [lastPt != null] {
    ctx.beginPath[];
    ctx.moveTo[lastPt.x, lastPt.y];
    ctx.lineTo[e.touches[0].pageX - offX,
             e.touches[0].pageY - offY];
    ctx.stroke[];
      }
    lastPt = {
       x: e.touches[0].pageX - offX,
       y: e.touches[0].pageY - offY
       };
     }

 function end[e] {
 for[var i=0; i

Bài Viết Liên Quan

Chủ Đề