How do i take the input quote from a user and shuffle it then put every letter separate in a table in JavaScript

Ray

I have the following typscript.

it's supposed to randomize the quote that the user input

quoteReady: boolean = false;

randomizQuote(array);

{
  this.quoteReady = true;

  this.quote = array;

  for (var i = array.length - 1; i > 0; i--) {
    var j = Math.floor(Math.random() * (i + 1));
    var temp = array[i];
    array[i] = array[j];
    array[j] = temp;
  }
}

2.And this is what i put in the html and what i want to do is to take the randomized quote and put 2 to 3 lettres of it in each table

<section *ngIf="quoteReady">
  <table class="table table-bordered table-hover table-responsive">
    <thead>
      <td>
        <tr *ngFor="let quo of quote">{{ citation }}</tr> //i want to insert a
        randome 2 to 3 //letters from the quote here
      </td>

      <td>
        <tr *ngFor="let quo of quote">{{ array }}</tr>
      </td>

      <td>
        <tr *ngFor="let quo of quote">{{ array }}</tr>
      </td>

      <td>
        <tr *ngFor="let quo of quote">{{ array }}</tr>
      </td>

      <td>
        <tr *ngFor="let quo of quote">{{ array }}</tr>
      </td>
    </thead>
  </table>
</section>

So, I am not sure why this is not giving the output.

JSmith

based on this answer

you could do in your ts

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

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
randomQuote = [];
numberOfLetters = 3
quote = "abcdefghijklmonopqrstuwxyz".split('');
quoteIndexes = {}

 ngOnInit(){
  while (this.randomQuote.length < this.numberOfLetters){
    let index = -1;
    do {
      index = Math.floor(Math.random() * this.quote.length);
      this.quoteIndexes[index] = true;
    } while (!(index in this.quoteIndexes))
    this.randomQuote.push(this.quote[index]);
  }
 }
}

then

<td>
  <tr *ngFor='let letter of randomQuote'>{{letter}}</tr>
</td>

here you absolutely need to have a number of letter less or equal to the quote length also make sure to avoid empty quotes

stackBlitz demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to insert one letter of the input quote of a user inside the table?

How do i take input from user and search api?

How do I get user input from separate classes

how do you get the first letter of a name from user input and put it into a if loop?

How do I get my (if "input" in list) to check every letter of the input and not just the first letter of input?

How do I take input from a bootstrap search bar and put it into a ajax call to retrieve data?

Trying to create a guess my letter code. How do I incorporate the case where the input char from the user equals my letter?

How do I compare user input to an uppercase letter string in a list?

How do I only accept capital letter as user input?

How do I get every line from a text file and put it in a website table?

How do I take an equation from a string and solve it then put the answer back into a string in javascript?

How do I take font input from the user in c# WinForms

How can I extract rows from a table and put into a separate file?

how do I take user input data as a dictionary?

How do I take in user input in discord.py

How do I put user's input from inputbox into a cell [VBA]

How to take input from the user in Javascript, while loading the code.

How can I take input from user and store it in a vector?

How can I take a input from user and change it with setState?

How do I add multiple lines of txt into an array and compare each letter to a user-input letter?

How do I take the output from a shuffle function and moves around DOM elements?

Read input from a file, capitalize first letter, make every other letter lowercase, and output into a separate file

How do I take an integer and put every number leading up to it in an array?

How do I use user input from one editable table and use it for the next table

How do I take the string returned from gen_results_table in PHP SDK and convert it to a Javascript array?

How do I make random shuffle work on a list of names input by the user?

How do I get shuffle() from Collections to not modify every array in a list?

How do you shuffle a table of images every second on the click of a button?

How do i make the user input a number, and if the user inputs a letter it returns an error - VB.net