Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/backend/src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import mongoose from "mongoose";
import fs from 'fs';
import { fileURLToPath } from 'url';
import path from 'path';
import { config } from 'dotenv'; // for loading mongodb url from .env.local file

config({path:'.env.local'});

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// const mongoUrl = `mongodb+srv://${uname}:${pw}@cluster0.oypxwnq.mongodb.net/?retryWrites=true&w=majority`;
const mongoUrl = "mongodb://127.0.0.1:27017/counting";
//const mongoUrl = `mongodb+srv://${uname}:${pw}@cluster0.oypxwnq.mongodb.net/?retryWrites=true&w=majority`;
//const mongoUrl = "mongodb://127.0.0.1:27017/counting";
const mongoUrl = process.env.MONGODB_URL;

async function connectToDb(){
try {
Expand Down
4 changes: 3 additions & 1 deletion apps/backend/src/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { config } from 'dotenv';
import {connectToDb} from './db.js';
import express from 'express';
import './database/userDetails.js';
Expand All @@ -11,7 +12,8 @@ import fetch from 'node-fetch';
import cors from 'cors';
import path from 'path';
import { fileURLToPath } from 'url';
import { config } from 'dotenv';
//import { config } from 'dotenv'; // might move it before importing the db.js file

// change from apps/backend/.env.local to .env.local to enable environment variables to be loaded on server
config({path:'.env.local'});

Expand Down
17 changes: 14 additions & 3 deletions apps/frontend/src/pages/basePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,24 @@ function basePage() {

const handleTrayClick = (trayType) => {
setSelectedTray(trayType);
if (trayType === "greenTray") {
textToSpeech("Correct");
// if the correct tray has been clicked
if (trayType === "greenTray" && baseData.pages[currentPage].greenTray[0].biscuits.length === baseData.pages[currentPage].cookies.length) {
textToSpeech("Green is correct, Good job!");
}
else if (trayType === "purpleTray" && baseData.pages[currentPage].purpleTray[0].biscuits.length === baseData.pages[currentPage].cookies.length){
textToSpeech("Purple is correct, Well done!");
}
// if the wrong tray has been clicked
else if (trayType === "greenTray" && baseData.pages[currentPage].greenTray[0].biscuits.length !== baseData.pages[currentPage].cookies.length) {
const explanation = `No, ${trayType} has ${baseData.pages[currentPage].greenTray[0].biscuits.length} cookies. Try again!`;
textToSpeech(explanation);
}
else{
textToSpeech("Incorrect");
const explanation = `Wrong answer, ${trayType} has ${baseData.pages[currentPage].purpleTray[0].biscuits.length} cookies. Try again!`;
textToSpeech(explanation);
}
storeAnswer(currentPage, trayType);

};

const handleNextPage = () => {
Expand Down
Loading