Lab Assignment - React Native
Lab Assignment - React Native
TASK 1: Write a JavaScript program that computes and displays the average marks of the following students.
Then, show the average letter grade. Display the names of the students with a mark higher than the average.
*students is an array of student objects,that has two properties: a student’s name and their mark
● function computeAvg(students) – returns the average of all students
● function convertToLetterGrade(mark) - returns the corresponding letter grade to a mark
● function markGreaterThanAvg(students, average) - does not return a value, displays on the console (using
console.log) the students’ name and mark that are higher than the average
CODE:
const students = [
{ name: 'Diana', mark: 82 },
{ name: 'Victor', mark: 67 },
{ name: 'Anne', mark: 76 },
{ name: 'Izzie', mark: 94 },
{ name: 'Thomas', mark: 72 }
];
function computeAvg(students) {
let total = 0;
students.forEach(student => {
total += student.mark;
});
return total / students.length;
}
function convertToLetterGrade(mark) {
if (mark >= 90) return 'A';
else if (mark >= 80) return 'B';
else if (mark >= 70) return 'C';
else if (mark >= 60) return 'D';
else return 'F';
}
class Student {
constructor(name, mark) {
this.name = name;
this.mark = mark;
}
}
Description: This exercise calculates the average mark of the students, converts that average mark to a letter
grade, and then prints the students who scored higher than the average.
Visit the link to view the work:
https://replit.com/@pcomputer813/Assignment-1-Ex1#index.js
Output:
TASK 2:
React Native Ex.
Basic Layout and Styling In the App component create a simple layout with 3 boxes. Use the View component for the
layout and the boxes themselves. Each box should have a height and a width, and the layout of the boxes should be styled
with Flexbox.
CODE:
import React from 'react';
import { View, StyleSheet } from 'react-native';
Description: This exercise creates a simple layout featuring three green boxes displayed horizontally. Each box
varies in size: the first box is small, the second is medium, and the third is large. The boxes are evenly spaced
within a light gray background, showcasing a clean and visually appealing arrangement that highlights basic
Flexbox styling techniques in React Native.
Visit the link to view the work:
https://replit.com/@pcomputer813/React-Native-Ex2-Assignment-1#App.js
Output:
TASK 3:
A Simple Profile Card
The goal of this exercise is to create a profile card with an image, name, and short description. Use Flexbox to arrange the
items and style them. You should use the View, Image, and Text components to build the card.
CODE:
import React from 'react';
import { View, Image, Text, StyleSheet } from 'react-native';