Question

In: Computer Science

This is done by using Angular in Visual code: Can you please give examples of the...

This is done by using Angular in Visual code:

Can you please give examples of the following?

1. Use Math.random function to generate a number between 20 and 100 and then use the ngSwitch directive to display a letter grade based on this class grading policy.

a. add implements OnInit to the AppComponent class

b. add variable x in the AppComponent class

c. add ngOnInit(){ this.x = Math.floor(Math.random()*10);}

d. add {{x}} in the app.components.html file

e. You should see numbers from 1-9 when you refresh the page

f. Change formula in #c to generate numbers from 20 to 100.

g. Change {{x}} in #d to ngSwitch directive

*****I am unable to get the ngSwitch directive to work for step g to display the letter grade A-F. Some help to get the ngSwitch to work would help*****

My codes are below

app.component.html

  

  

<div style="text-align:center">

  <h1>

  <span> Welcome to {{x}}!</span>

  </h1>

</div>

<p>Your grade: {{x}} </p>

<div [ngSwitch]= "switch_expression">

  <p *ngSwitchCase="90-100">A</p>

  <p *ngSwitchCase="80-89">B</p>

  <p *ngSwitchCase="70-79">C</p>

  <p *ngSwitchCase="60-69">D</p>

  <p *ngSwitchDefault>F</p>

</div>

app.component.ts

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

@Component({

  selector: 'app-root',

  templateUrl: './app.component.html',

  styleUrls: ['./app.component.css']

})

export class AppComponent implements OnInit {

  title = 'module8';

  clicked = false;

  condition = true;

  x: number;

  switch_expression = "x"

ngOnInit() {

  this.x = Math.floor(Math.random()*(100-20+1)+20);

}

}

Solutions

Expert Solution

app.component.html

<div style="text-align:center">
  <h1>
  <span> Welcome to {{x}}!</span>
  </h1>
</div>

<p>Your grade: {{x}} </p>
<!-- Here you should write your expression based that value value switch case work -->
<div [ngSwitch]="y">        
  <p *ngSwitchCase="10">A</p>
  <p *ngSwitchCase="9">A</p>
  <p *ngSwitchCase="8">B</p>
  <p *ngSwitchCase="7">C</p>
  <p *ngSwitchCase="6">D</p>
  <p *ngSwitchDefault>F</p>
</div>

app.component.ts

import { Component, OnInit} from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'module8';
  x: number;
  y: number;
ngOnInit() {
  this.x= Math.floor(Math.random()*(100-20+1)+20);   //Its generate random number between 20 to 100
  this.y=Math.floor((this.x/10));           //here it devide the nunber by 10 so we get 1st digit on which we can decide range
                                        //for ex if x is 67 then y 6 so we can decide that its fall under 60 to 69 
  }
}

Output:

app.component.html

app.component.ts


Related Solutions

How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your own words)
Please give me 2 examples of angular analoge of newton's 3rd law of motion on cricket...
Please give me 2 examples of angular analoge of newton's 3rd law of motion on cricket and 2 examples of angular analoge of the 2nd law of motion on cricket sport and examples of co efficient of restitution, conservation of momentum and transfer of angular momentum on cricket please answer in the form of screenshots or videos
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
please . Can you give examples of problems with regression and correlation and show calculated you...
please . Can you give examples of problems with regression and correlation and show calculated you how to do it in detail?
Please describe the steps taken in Data Preprocessing. Give examples and explain what was done in...
Please describe the steps taken in Data Preprocessing. Give examples and explain what was done in each of these steps. PLEASE PROVIDE DETAILED EXPLANATION , SO I CAN UNDERSTAND EASILY COURSE : DATA MINING
How do I run javscript console on Visual Studio code? Please give exact detail for thumbs...
How do I run javscript console on Visual Studio code? Please give exact detail for thumbs up. I just downloaded VS code.
***This problem must be done using R so please provide the R code used to find...
***This problem must be done using R so please provide the R code used to find the solution. I have provided the data in data-wtLoss.txt below the question. I will also give "thumbs-up for correct R code" Thanks in advance.*** The file “data-wtLoss.txt” contains data on weight loss and self esteem evaluation at three time points over a period of three months for 34 individuals who are randomly selected from a residential area. These individuals are randomly assigned to one...
***This problem must be done using R so please provide the R code used to find...
***This problem must be done using R so please provide the R code used to find the solution. I have provided the data in data-wtLoss.txt below the question. I will also give "thumbs-up for correct R code" Thanks in advance.*** The file “data-wtLoss.txt” contains data on weight loss and self esteem evaluation at three time points over a period of three months for 34 individuals who are randomly selected from a residential area. These individuals are randomly assigned to one...
Consider the concepts of "judicial activism" and "judicial restraint." Can you give examples of each? Please...
Consider the concepts of "judicial activism" and "judicial restraint." Can you give examples of each? Please do so. Which judicial behavior do you believe best serves the country? Why?
Can you give examples of using functions in real life? By real life I understand not...
Can you give examples of using functions in real life? By real life I understand not only what we do in everyday living, but also science, economy, and similar.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT