dimanche 22 novembre 2020

How to Generate Two Random numbers in Typescript and Check whether both are same?

import { Component, OnInit } from '@angular/core';
import { from } from 'rxjs';

@Component({
  selector: 'app-play-match',
  templateUrl: './play-match.component.html',
  styleUrls: ['./play-match.component.css']
})
export class PlayMatchComponent implements OnInit {
  
  
  public teams = [
    "Annites Football Club","Devans Football CLub", "Marians Football Club",
            "Loyolian Football Club","Avian Football Club"
  ];

  public homeTeamSelect: number = Math.floor(Math.random() * this.teams.length);
  public opponentTeamSelect:number = Math.floor(Math.random() * this.teams.length);


  if (homeTeamSelect:number === opponentTeamSelect:number) {
    
  }
  



  

  constructor() { }

  ngOnInit(): void {
    this.loadScript('../assets/js/play.js')
  }

  public loadScript(url : string){
    const body = <HTMLDivElement> document.body;
    const script = document.createElement('script');
    script.innerHTML = '';
    script.src = url;
    script.async = false;
    script.defer = true;
    body.appendChild(script);

  }
  

 
  

}

on if area it throws an error cannot find the opponentTeamSelect. How can I fix this error? Please Help me. I need to Generate two random numbers between the size of array or the length of array and select two clubs from this array and set it into variable. but in my case both random numbers are can not be same. So anyone can give me proper solution for this manner? Thank you.




Aucun commentaire:

Enregistrer un commentaire