Within the Angular2 program below, I am attempting to have the system randomly select four choices from either 0 or 1. The desired output is achieved without any errors being reported in the console. However, my IDE is displaying the following error message:
https://i.sstatic.net/AosIk.png
I attempted changing Number
to number
but this resulted in a different error:
https://i.sstatic.net/RhplA.png
Component Code
import {Component} from 'angular2/core';
import {OnInit} from 'angular2/core';
@Component(
{
selector: 'puzzle',
template: `
<section class="combination">
I: {{ switch1Number }}<br>
II: {{ switch2Number }}<br>
III: {{ switch3Number }}<br>
IV: {{ switch4Number }}
</section>
`
})
export class PuzzleComponent implements OnInit {
switch1Number = Number;
switch2Number = Number;
switch3Number = Number;
switch4Number = Number;
ngOnInit() {
// Math.randon gives a random decimal value between 0 & 1.
// Math..round rounds it to 0 or 1
this.switch1Number = Math.round(Math.random());
this.switch2Number = Math.round(Math.random());
this.switch3Number = Math.round(Math.random());
this.switch4Number = Math.round(Math.random());
console.log(this.switch1Number, this.switch2Number, this.switch3Number, this.switch4Number);
}
}