Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Chuck Norris Facts!
#12
(04-21-2023, 08:11 PM)dbox Wrote: Have you ever wished you had a desktop background that would tell you random Chuck Norris facts?  Haven't we all?

Well now your wish has become a reality:
Code: (Select All)
Dim img
img = _LoadImage("https://images01.military.com/sites/default/files/styles/full/public/2021-04/chucknorris.jpeg.jpg?itok=2b4A6n29")
_PutImage , img
_Fullscreen

Do
    _Delay 2

    Dim result As Object
    result = Fetch("https://api.chucknorris.io/jokes/random")

    If result.ok Then
        Dim obj As Object
        obj = JSON.parse(result.text)
        Say obj.value   
    End If
Loop


Sub Say (text As String)
    $If Javascript Then
        var synth = window.speechSynthesis;
        if (synth) {
            var utterance = new SpeechSynthesisUtterance(text);
            synth.speak(utterance);   
            while (synth.speaking) {
                await QB.sub__Delay(.5);
            }
            success = -1;
        }
    $End If
End Sub

View in QBJS

This is really great. Questions:

1. Everything is JS in QBJS - except how you write it using QB syntax or not, still transpiles to JS, right?
2. Fetch! That's awesome, does this have a QB64 counterpart?
3. JSON.parse - native JS inside the QBJS part - it's a little confusing to me - this is javascript inside of QBJS but without $If Javascript like lower down - can you explain how you do that, or how we would know what we can do? If it's in the docs, I'm sorry.

Thanks for sharing this great and simple example.
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply


Messages In This Thread
Chuck Norris Facts! - by dbox - 04-21-2023, 08:11 PM
RE: Chuck Norris Facts! - by mnrvovrfc - 04-21-2023, 11:24 PM
RE: Chuck Norris Facts! - by SMcNeill - 04-22-2023, 10:55 AM
RE: Chuck Norris Facts! - by dbox - 04-22-2023, 11:04 AM
RE: Chuck Norris Facts! - by SMcNeill - 04-23-2023, 01:29 AM
RE: Chuck Norris Facts! - by CharlieJV - 04-23-2023, 05:59 PM
RE: Chuck Norris Facts! - by bplus - 04-22-2023, 12:41 PM
RE: Chuck Norris Facts! - by dbox - 04-22-2023, 01:04 PM
RE: Chuck Norris Facts! - by aurel - 04-23-2023, 10:34 AM
RE: Chuck Norris Facts! - by dbox - 04-23-2023, 11:25 PM
RE: Chuck Norris Facts! - by grymmjack - 04-27-2023, 03:13 AM
RE: Chuck Norris Facts! - by grymmjack - 04-27-2023, 03:17 AM
RE: Chuck Norris Facts! - by mnrvovrfc - 04-27-2023, 03:24 AM
RE: Chuck Norris Facts! - by dbox - 04-27-2023, 11:45 AM
RE: Chuck Norris Facts! - by grymmjack - 04-28-2023, 12:53 AM
RE: Chuck Norris Facts! - by mnrvovrfc - 04-27-2023, 04:35 PM



Users browsing this thread: 3 Guest(s)