Skip to content

Commit

Permalink
Update the commment as the JSDoc format
Browse files Browse the repository at this point in the history
  • Loading branch information
cao00121 committed Dec 10, 2023
1 parent efb96db commit 167ab6e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
26 changes: 21 additions & 5 deletions lab-4/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,42 @@
console.log('setFontColor()' + ' -- Update the font color of the element');
console.log('setTheme()' + ' -- Update the page theme from theme1 to theme4');

// function to update the title c
/** This function will update the title text by using the query selector to select the "#title" and
* update the textContent with the updateText parameter.
* @param {string} updateText - The text to update the title with.
* @returns "Title has been updated." - returns a string to confirm the title has been updated.
*/
function setTitle(updateText) {
const titleText = document.querySelector('#title');
titleText.textContent = updateText;
titleText.textContent = updateText;
return 'Title has been updated.';
}

// function to update the background color
/** This function will update the background color of the page by usign the query selector to select the
* body element and update the backgroundColor with the updateColor parameter.
* @param {string} updateColor - The color to update the background with.
* @returns - "Background color has been updated." - returns a string to confirm the background color has been updated.
*/
function setBackgroundColor(updateColor) {
document.body.style.backgroundColor = updateColor;
return 'Background color has been updated.';
}

// function to update the font color
/** This function will update the font color of the page by using the query selector to select the
* body element and update the color with the updateColor parameter.
* @param {string} updateColor - The color to update the font with.
* @returns - "Font color has been updated." - returns a string to confirm the font color has been updated.
*/
function setFontColor(updateColor) {
document.body.style.color = updateColor;
return 'Font color has been updated.';
}

// function to set the theme
/** This function will update the theme of the page by using the query selector to select the body element
* and update the classList with the switchTheme parameter.
* @param {string} switchTheme - The theme to update the page with.
* @returns - "Current theme is ${switchTheme}." - returns a string to confirm the theme has been updated.
*/
function setTheme(switchTheme) {
const bodyTheme = document.body;

Expand Down
23 changes: 19 additions & 4 deletions lab-5/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ console.log('Sample Input -- Book 1: addBook(\'One Hundred Years of Solitude\',
// Create an empty book catalogue
let bookCatalogue = [];

// Create function to add books
/** This function will add a new book to the catalogue.
*
* @param {string} title - The title of the book.
* @param {string} author - The author of the book.
* @param {string} genre - The genre of the book.
* @returns - "Book added" - returns a string to confirm the book has been added.
*/
function addBook (title, author, genre) {
let newBook = {
title: title,
Expand All @@ -19,18 +25,27 @@ function addBook (title, author, genre) {
return 'Book added';
}

//Create function to display a list of book titles and the indexes
/** This function will display a list of book titles and their indexes in the catalogue.
*
* @returns - "No books yet." - returns a string to confirm there are no books in the catalogue.
*/
function showBooks() {
if (bookCatalogue.length === 0){
return 'No books yet.'
}
for (let i = 0; i < bookCatalogue.length; i++) {
let i = 0;
while (i < bookCatalogue.length) {
console.log(i + ': ' + bookCatalogue[i].title);
i++;
}
}


// Create function to display the details of a book
/** This function will display the details of a book, including the book's title, author, and genre.
*
* @param {number} index - The index of the book in the catalogue.
* @returns - "No books yet." - returns a string to confirm there are no books in the catalogue.
*/
function showBook (index) {
if (bookCatalogue.length === 0) {
return 'No books yet.'
Expand Down

0 comments on commit 167ab6e

Please sign in to comment.