0
Unexpected token
I have got error in Node.js course with ... 3dots
7 Antworten
+ 2
Václav Dostál
I am also using Android 6, there is no problem running that code.
Try to find Android WebView in phone's apps list and update it, hope it helps ...
+ 1
Attach your code please. How can we tell you about the problem without seeing the code.
+ 1
It should work. The reason why it doesn't recognise ... as a valid token might be that you are using an old version of browser that does not support ES6. ES6 is also not supported on phones with a very old Android version, like maybe < 7 (I'm not sure). If possible try running on a newer browser or device. If not, then use ES5 supported alternatives. For example, the code you are trying to write can be written as:
function containsAll(arr) {
for (let num of arguments) { // arguments is an array of any extra arguments passed to a function
if (arr.indexOf(num) === - 1)
return false
return true
}
let x = [2, 4, 6, 7]
console.log(containsAll(x, 2, 4, 7))
console.log(containsAll(x, 6, 4, 9))
This code should work
+ 1
Thaks, it makes sense. I am using Android 6, so there is problem.
0
function containsAll(arr, ...nums) {
for (let num of nums) {
if (arr.indexOf(num) === -1) {
return false;
}
}
return true;
}
let x = [2, 4, 6, 7];
console.log(containsAll(x, 2, 4, 7));
console.log(containsAll(x, 6, 4, 9));
0
And what about this code: class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
for(let num of arguments) {
console.log(num);
}
}
var x = new Add("hehe", "hoho", "haha", "hihi", "huhu");
var y = new Add("this", "is", "awesome");
var z = new Add("lorem", "ipsum", "dolor", "sit", "amet", ",", "consectetur", "adipiscing", "elit");
x.print();
y.print();
z.print();
0
You were missing the `print` method definition, the for loop should be inside `print` method, and it should log elements of `this.words` rather than `arguments`, because `print` method is not accepting any argument.
With that being fixed, code runs okay.