Need help transferring code from vanilla Js to Nativescript


#1

Im just creating a simple array; It consists of a media slider with 3 types of data: strings, images and audio. It works fine when i run it in the browser but im having trouble making it work in Nativescript.

Js:

var image = document.getElementById(‘image’);

var text = document.getElementById(‘text’);

var audio = document.getElementById(‘audio’);

//Audio array
var audioArray = [
‘Audios/word1.mp3’,
‘Sounds/img1.mp3’,
‘Audios/word2.mp3’,
‘Sonidos/img2.mp3’,
‘Audios/word3.mp3’,
‘Sonidos/img3.mp3’,
];

var audioIndex = 0;

//Visuals array
var visualArray = [
“word 1”,
‘Images/word1.png’,
“word 2”,
‘Images/word2.png’,
“word 3”,
‘Images/word3.png’,
];

var visualIndex = 0;

function slide(){

text.innerHTML = visualArray[visualIndex];

image.setAttribute(‘src’, visualArray[visualIndex]);

audio.setAttribute(‘src’, audioArray[audioIndex]);

audio.play();

}

function next(){

visualIndex++;
audioIndex++;

if(visualIndex > visualArray.length-1){
visualIndex = 0;
audioIndex = 0;
}

setTimeout(slide, 1000);

}

slide();


#2

Hey @gersgv, have you seen the NativeScript getting started tutorial https://docs.nativescript.org/tutorial/chapter-0 ? It should be enough to set you off.