javascript意外的令牌

时间:2017-10-07 19:19:49

标签: javascript

有人请帮助解决以下代码中的错误。它说"意外的令牌"同时验证Java Validate website - esprima.org

上的javascript代码

`

function add1()
{
 var size = 8;
 var widthOfGrid = size;
 var lenthOfGrid = size;
 var linenumber = 1;
 for (i = 1 ; i<=size ; i += 1 )
   {
    for (j = 1 ; j<=size ; j += 1)
      {
       If (i % 2 === 0)
        {
          console.log(" " +  "#");
        }
        else
        {
         console.log("#" + " ");
        }
       }
    }
}

`

3 个答案:

答案 0 :(得分:1)

在Javascript中没有If语句。 Javascript是case-sensitive语言将其写在lower case - if中。并且还重构代码,你有一些未使用的变量。

答案 1 :(得分:0)

问题是var request = require("request"); var cheerio = require("cheerio"); var fs = require('fs'); var concurrent_requests = 0; var queue = []; var baseUrl = "https://angularjs.org/"; function makeApiCall(url){ if(url) { queue.unshift(url); } if(concurrent_requests<5) { var nextUrl = queue.pop(); if(nextUrl) { concurrent_requests++; request(nextUrl, function (error, response, body) { var invalidUrl; concurrent_requests--; if(body) { var $ = cheerio.load(body); var anchors = $("a"); var data = ""; for (var i = 0; i < anchors.length; i++) { url = $(anchors[i]).attr("href"); if(!url || url === "#" || url === "javascript:void(0)"){ invalidUrl = true; } else{ invalidUrl = false; } if (!invalidUrl) { makeApiCall(url); data += url + ", " + nextUrl + "\n"; } } //console.log(data); fs.appendFile('urls.csv',data, function (err) { if (err) throw err; }); } else{ makeApiCall(); } }); } } console.log(concurrent_requests); } makeApiCall(baseUrl); 应该是小写的。

代码应该是这样的:

from PyQt5 import QtWidgets
from PyQt5 import QtCore, QtMultimedia
from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal, QByteArray, QIODevice, QFileInfo
from PyQt5.QtMultimedia import QAudioDecoder, QAudioFormat, QMediaObject, QAudioBuffer, QAudioOutput, QAudio

class AudioDecoder(QObject):
  def __init__(self):
    super(AudioDecoder,self).__init__()
    self.desiredFormat = QAudioFormat()
    self.desiredFormat.setChannelCount(2)
    self.desiredFormat.setCodec('audio/pcm')
    self.desiredFormat.setSampleType(QAudioFormat.UnSignedInt)
    self.desiredFormat.setSampleRate(48000)
    self.desiredFormat.setSampleSize(16)

    self.decoder = QAudioDecoder()
    self.decoder.setAudioFormat(self.desiredFormat)
    fs = QFileInfo('test.wav')
    self.decoder.setSourceFilename(fs.absoluteFilePath())
    print('File exists:' + str(fs.exists()))

    #self.connect(decoder,bufferReady(),None,readBuffer())
    self.decoder.bufferReady.connect(self.readBuffer)
    self.decoder.finished.connect(self.play)
    self.decoder.error.connect(self.error)
    self.decoder.stateChanged.connect(self.stateChanged)
    self.decoder.positionChanged.connect(self.positionChanged)
    self.decoder.bufferAvailableChanged.connect(self.bufferAvailableChanged)

    #using this to determine if we need to start byte array or append to it
    self.readamount = 0

    #Expect this to be true since we haven't started yet
    print('Decoder stopped:' + str(self.decoder.state() == QAudioDecoder.StoppedState))
    self.decoder.start()
    print('Init finished, Decoder started?')
  def bufferAvailableChanged(self):
   print(str(self.decoder.bufferAvailable()))
  def positionChanged(self):
    print(str(self.decoder.position())+'/'+str(self.decoder.duration()))
  def stateChanged(self):
    #Confirm state is what we expect
    print('Decoder state changed?')
    print('Decoder stopped?:' + str(self.decoder.state() == QAudioDecoder.StoppedState))
    print('Decoder decoding?:' + str(self.decoder.state() == QAudioDecoder.DecodingState))
  def error(self):
    print('Decoder error?')
    print(self.decoder.errorString())
  def readBuffer(self):
    print('Decoder ready for reading?')
    buffer = self.decoder.read()
    count = buffer.byteCount()
    print('Bytecount in buffer:' + str(count))
    if self.readamount == 0:
      self.ba = QByteArray()
      self.ba.fromRawData(buffer.constData().asstring(count))
      self.readamount = count
    else:
      self.ba.append(buffer.constData().asstring(count))
    print('Bytearray size:' + str(self.ba.length()))
  def play(self):
    print('Decoding finished, ready to play')

app = QtWidgets.QApplication([''])
ad = AudioDecoder()

import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
# press Ctrl+C to exit

app.exec_()

答案 2 :(得分:0)

function add1()
{
 var size = 8;
 var widthOfGrid = size;
 var lenthOfGrid = size;
 var linenumber = 1;
 for (i = 1 ; i<=size ; i += 1 )
   {
    for (j = 1 ; j<=size ; j += 1)
      {
       if (i % 2 === 0)
        {
          console.log(" " +  "#");
        }
        else
        {
         console.log("#" + " ");
        }
       }
    }
}

工作代码,你忘了把你的if用小写