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
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?
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 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
I need this code in C++ form using visual studios please: Create a class that simulates...
I need this code in C++ form using visual studios please: Create a class that simulates an alarm clock. In this class you should: •       Store time in hours, minutes, and seconds. Note if time is AM or PM. (Hint: You should have separate private members for the alarm and the clock. Do not forget to have a character variable representing AM or PM.) •       Initialize the clock to a specified time. •       Allow the clock to increment to the...
NOTE: This is done using Visual Basic. Create an application named You Do It 2. Add...
NOTE: This is done using Visual Basic. Create an application named You Do It 2. Add a text box, a label, and a button to the form. Enter the following three Option statements above the Public Class clause in the Code Editor window: Option Explicit On, Option Strict Off, and Option Infer Off. In the button’s Click event procedure, declare a Double variable named dblNum. Use an assignment statement to assign the contents of the text box to the Double...
NOTE: This is done using Visual Basic. Create an application named You Do It 1. Add...
NOTE: This is done using Visual Basic. Create an application named You Do It 1. Add a text box, a label, and a button to the form. The button’s Click event procedure should store the contents of the text box in a Double variable named dblCost. It then should display the variable’s contents in the label. Enter the three Option statements above the Public Class clause in the Code Editor window, and then code the procedure. Save the solution and...
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.
I am trying to write code for a program in Visual Studo using Visual Basic programming...
I am trying to write code for a program in Visual Studo using Visual Basic programming language that computes the factorial of an entered number by using a For Loop. My problem is that it keeps re-setting the variable for Factorial. Below is my code if anyone can help. I want it to multiply the given number by that number - 1, then continuing to do so until it hits zero without multiplying by zero. Private Sub BtnCalculate_Click(sender As Object,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT