Skip to content

Designed to convert numbers from string format to numerical format, handling both decimal commas and dots.Validates user input against a correct answer.Executes user-defined functions for correct and incorrect answers.

DovzhukTimofii/NumericInputValidatorByDT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Purpose:

Designed to convert numbers from string format to numerical format, handling both decimal commas and dots. Validates user input against a correct answer. Executes user-defined functions for correct and incorrect answers.

Properties:

userInput: Stores the user's input as a string. correctAnswerValue: Stores the correct answer as a string. correctAnswerFun: Stores a function to be executed when the answer is correct. incorrectAnswerFun: Stores a function to be executed when the answer is incorrect.

Methods:

setUserInput(userInput): Sets the user's input. setCorrectAnswer(correctAnswer): Sets the correct answer. setAnswers(correctAnswerFun, incorrectAnswerFun): Sets the functions to be executed for correct and incorrect answers. convertNumber(input): Converts a string to a number, handling decimal commas and dots. checkAnswer(): Checks the user's input against the correct answer and calls the appropriate functions based on the result.

Create an instance of the class: const converter = new ConverterOfNumber(); Set the user's input, correct answer, and answer handling functions:

converter.setUserInput("1,5").setCorrectAnswer("1.5").setAnswers(
   () => console.log("Correct!"),
   () => console.log("Incorrect.")
);

Check the answer:

converter.checkAnswer();

installation of the library:

npm i numberformatcomparator

import a library:

import { ConverterOfNumber } from "numberformatcomparator";

import { AnswerCallback } from "./app"; // import type

Example:

converter.setUserInput("2").setCorrectAnswer("2").checkAnswer(); // Output: Correct!
converter.setUserInput("1,3").setCorrectAnswer("1.3").checkAnswer(); // Output: Correct!
converter.setUserInput("abc").setCorrectAnswer("1.3").checkAnswer(); // Output: Incorrect.

About

Designed to convert numbers from string format to numerical format, handling both decimal commas and dots.Validates user input against a correct answer.Executes user-defined functions for correct and incorrect answers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published