SHARE
TWEET

Untitled

a guest Sep 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculate() {
  2.     let viiteNumero = document.getElementById('viite').value;
  3.     let numerot = parseInt(document.getElementById('viite').value);
  4.     document.getElementById('viite').value = "";
  5.     let arrayNumerot = Array.from(numerot.toString()).map(Number);
  6.  
  7.     let summa1 = 0;
  8.     let summa3 = 0;
  9.     let summa7 = 0;
  10.     let pituus = arrayNumerot.length-2;
  11.  
  12.     for (let i = pituus; i >= 0; i=i-3) {
  13.         summa7 = (arrayNumerot[i]*7)+summa7;
  14.         console.log(arrayNumerot[i]);
  15.     }
  16.  
  17.     for (let i = pituus-1; i >= 0; i=i-3) {
  18.         summa3 = (arrayNumerot[i]*3)+summa3;
  19.     }
  20.  
  21.     for (let i = pituus-2; i >= 0; i=i-3) {
  22.         summa1 = arrayNumerot[i]+summa1;
  23.     }
  24.  
  25.     let yhteisSumma = summa1+summa3+summa7;
  26.     let tarkistus = 10-(yhteisSumma % 10);
  27.     if (tarkistus === 10) {
  28.         tarkistus = 0;
  29.     }
  30.  
  31.     if (arrayNumerot[pituus+1] === tarkistus) {
  32.         document.getElementById('result').innerHTML="Viitenumero " + viiteNumero + " on oikea";
  33.         document.getElementById('merkki').innerHTML="";
  34.     } else {
  35.         document.getElementById('result').innerHTML="Viitenumero on virheellinen"
  36.         document.getElementById('merkki').innerHTML="Tarkistusmerkki on: " + tarkistus;
  37.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top